diff --git a/exercises/03.compound-components/01.problem/toggle.tsx b/exercises/03.compound-components/01.problem/toggle.tsx index c9b50a4f..3ce5a32a 100644 --- a/exercises/03.compound-components/01.problem/toggle.tsx +++ b/exercises/03.compound-components/01.problem/toggle.tsx @@ -31,9 +31,7 @@ export function ToggleOff({ children }: { children: React.ReactNode }) { return <>{on ? null : children} } -export function ToggleButton( - props: Omit, 'on' | 'onClick'>, -) { +export function ToggleButton(props: React.ComponentProps) { // 🐨 get `on` and `toggle` from the ToggleContext with `use` const on = false const toggle = () => {} diff --git a/exercises/03.compound-components/01.solution/toggle.tsx b/exercises/03.compound-components/01.solution/toggle.tsx index 95189164..c0cd9f87 100644 --- a/exercises/03.compound-components/01.solution/toggle.tsx +++ b/exercises/03.compound-components/01.solution/toggle.tsx @@ -1,8 +1,8 @@ -import { use, useState } from 'react' +import { createContext, use, useState } from 'react' import { Switch } from '#shared/switch.tsx' type ToggleValue = { on: boolean; toggle: () => void } -const ToggleContext = React.createContext(undefined) +const ToggleContext = createContext(undefined) ToggleContext.displayName = 'ToggleContext' export function Toggle({ children }: { children: React.ReactNode }) { @@ -28,7 +28,7 @@ export function ToggleOff({ children }: { children: React.ReactNode }) { export function ToggleButton({ ...props -}: Omit, 'on' | 'onClick'>) { +}: Omit, 'on'>) { const { on, toggle } = use(ToggleContext)! return } diff --git a/exercises/03.compound-components/02.problem.validation/app.tsx b/exercises/03.compound-components/02.problem.validation/app.tsx index 0544e966..34deeebe 100644 --- a/exercises/03.compound-components/02.problem.validation/app.tsx +++ b/exercises/03.compound-components/02.problem.validation/app.tsx @@ -1,4 +1,4 @@ -import { Toggle, ToggleOn, ToggleOff, ToggleButton } from './toggle.tsx' +import { Toggle, ToggleButton, ToggleOff, ToggleOn } from './toggle.tsx' export function App() { return ( diff --git a/exercises/03.compound-components/02.problem.validation/toggle.tsx b/exercises/03.compound-components/02.problem.validation/toggle.tsx index 95189164..c0cd9f87 100644 --- a/exercises/03.compound-components/02.problem.validation/toggle.tsx +++ b/exercises/03.compound-components/02.problem.validation/toggle.tsx @@ -1,8 +1,8 @@ -import { use, useState } from 'react' +import { createContext, use, useState } from 'react' import { Switch } from '#shared/switch.tsx' type ToggleValue = { on: boolean; toggle: () => void } -const ToggleContext = React.createContext(undefined) +const ToggleContext = createContext(undefined) ToggleContext.displayName = 'ToggleContext' export function Toggle({ children }: { children: React.ReactNode }) { @@ -28,7 +28,7 @@ export function ToggleOff({ children }: { children: React.ReactNode }) { export function ToggleButton({ ...props -}: Omit, 'on' | 'onClick'>) { +}: Omit, 'on'>) { const { on, toggle } = use(ToggleContext)! return } diff --git a/exercises/03.compound-components/02.solution.validation/toggle.tsx b/exercises/03.compound-components/02.solution.validation/toggle.tsx index e4920d3c..2d337769 100644 --- a/exercises/03.compound-components/02.solution.validation/toggle.tsx +++ b/exercises/03.compound-components/02.solution.validation/toggle.tsx @@ -1,8 +1,8 @@ -import { use, useState } from 'react' +import { createContext, use, useState } from 'react' import { Switch } from '#shared/switch.tsx' type ToggleValue = { on: boolean; toggle: () => void } -const ToggleContext = React.createContext(undefined) +const ToggleContext = createContext(undefined) ToggleContext.displayName = 'ToggleContext' export function Toggle({ children }: { children: React.ReactNode }) { @@ -38,7 +38,7 @@ export function ToggleOff({ children }: { children: React.ReactNode }) { export function ToggleButton({ ...props -}: Omit, 'on' | 'onClick'>) { +}: Omit, 'on'>) { const { on, toggle } = useToggle() return } diff --git a/exercises/04.slots/01.problem.context/README.mdx b/exercises/04.slots/01.problem.context/README.mdx new file mode 100644 index 00000000..892c37f1 --- /dev/null +++ b/exercises/04.slots/01.problem.context/README.mdx @@ -0,0 +1 @@ +# Slot Context diff --git a/exercises/04.slots/01.solution/app.tsx b/exercises/04.slots/01.problem.context/app.tsx similarity index 79% rename from exercises/04.slots/01.solution/app.tsx rename to exercises/04.slots/01.problem.context/app.tsx index a7f61ea8..ca6334d4 100644 --- a/exercises/04.slots/01.solution/app.tsx +++ b/exercises/04.slots/01.problem.context/app.tsx @@ -17,7 +17,9 @@ export function App() {
+ {/* 🦉 feel free to test the id customization by passing an id here */} + {/* 🦉 feel free to test the prop merging by passing props here */} diff --git a/exercises/04.slots/01.problem/index.css b/exercises/04.slots/01.problem.context/index.css similarity index 100% rename from exercises/04.slots/01.problem/index.css rename to exercises/04.slots/01.problem.context/index.css diff --git a/exercises/04.slots/01.problem/index.tsx b/exercises/04.slots/01.problem.context/index.tsx similarity index 100% rename from exercises/04.slots/01.problem/index.tsx rename to exercises/04.slots/01.problem.context/index.tsx diff --git a/exercises/04.slots/01.problem.context/slots.tsx b/exercises/04.slots/01.problem.context/slots.tsx new file mode 100644 index 00000000..20ea7c3c --- /dev/null +++ b/exercises/04.slots/01.problem.context/slots.tsx @@ -0,0 +1,18 @@ +// 🦺 create a Slots type that's just an object of objects +// 🐨 create and export a SlotContext with that type and default it to an empty object + +// 🐨 create a useSlotProps hook which: +// 1. accepts props (any type) and slot (string) +// 2. gets the slots from the SlotContext +// 3. gets the props from the slot by its name +// 4. returns the merged props with the slot and given props + +export function Label(props: React.ComponentProps<'label'>) { + // 🐨 get the props from useSlotProps for a slot called "label" and apply those to the label + return