-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(accordion): document context (#3000)
* chore(accordion): document context * chore: update vue stories * chore: update vue stories * chore: fix icons path
- Loading branch information
Showing
16 changed files
with
392 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react/src/components/accordion/examples/context/focusedValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Accordion } from '@ark-ui/react/accordion' | ||
import { ChevronDownIcon } from 'lucide-react' | ||
|
||
export const ContextFocusedValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <span>Focused item: {context.focusedValue}</span>} | ||
</Accordion.Context> | ||
{['React', 'Solid', 'Vue'].map((item) => ( | ||
<Accordion.Item key={item} value={item}> | ||
<Accordion.ItemTrigger> | ||
What is {item}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
))} | ||
</Accordion.Root> | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/react/src/components/accordion/examples/context/getItemState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Accordion } from '@ark-ui/react/accordion' | ||
import { ChevronDownIcon } from 'lucide-react' | ||
|
||
export const ContextGetItemState = () => { | ||
const items = [{ value: 'React' }, { value: 'Solid', disabled: true }, { value: 'Vue' }] | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => { | ||
const itemState = context.getItemState(items[2]) | ||
return ( | ||
<> | ||
<b>Vue State: </b> | ||
<span>Disabled: {itemState.disabled ? 'Y' : 'N'} </span> | ||
<span>Expanded: {itemState.expanded ? 'Y' : 'N'} </span> | ||
<span>Focused: {itemState.focused ? 'Y' : 'N'} </span> | ||
</> | ||
) | ||
}} | ||
</Accordion.Context> | ||
{items.map((item) => ( | ||
<Accordion.Item key={item.value} {...item}> | ||
<Accordion.ItemTrigger> | ||
What is {item.value}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item.value} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
))} | ||
</Accordion.Root> | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/react/src/components/accordion/examples/context/setValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Accordion } from '@ark-ui/react/accordion' | ||
import { ChevronDownIcon } from 'lucide-react' | ||
|
||
export const ContextSetValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <button onClick={() => context.setValue(['Vue'])}>Select Vue</button>} | ||
</Accordion.Context> | ||
{['React', 'Solid', 'Vue'].map((item) => ( | ||
<Accordion.Item key={item} value={item}> | ||
<Accordion.ItemTrigger> | ||
What is {item}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
))} | ||
</Accordion.Root> | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/react/src/components/accordion/examples/context/value.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Accordion } from '@ark-ui/react/accordion' | ||
import { ChevronDownIcon } from 'lucide-react' | ||
|
||
export const ContextValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <span>Selected items: {context.value.join(', ')}</span>} | ||
</Accordion.Context> | ||
{['React', 'Solid', 'Vue'].map((item) => ( | ||
<Accordion.Item key={item} value={item}> | ||
<Accordion.ItemTrigger> | ||
What is {item}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
))} | ||
</Accordion.Root> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/solid/src/components/accordion/examples/context/focusedValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Accordion } from '@ark-ui/solid/accordion' | ||
import { ChevronDownIcon } from 'lucide-solid' | ||
import { Index } from 'solid-js' | ||
|
||
export const ContextFocusedValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <span>Focused item: {context().focusedValue}</span>} | ||
</Accordion.Context> | ||
<Index each={['React', 'Solid', 'Vue']}> | ||
{(item) => ( | ||
<Accordion.Item value={item()}> | ||
<Accordion.ItemTrigger> | ||
What is {item()}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item()} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
)} | ||
</Index> | ||
</Accordion.Root> | ||
) | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/solid/src/components/accordion/examples/context/getItemState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Accordion } from '@ark-ui/solid/accordion' | ||
import { ChevronDownIcon } from 'lucide-solid' | ||
import { Index } from 'solid-js' | ||
|
||
export const ContextGetItemState = () => { | ||
const items = [{ value: 'React' }, { value: 'Solid', disabled: true }, { value: 'Vue' }] | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => { | ||
const itemState = context().getItemState(items[2]) | ||
return ( | ||
<> | ||
<b>Vue State: </b> | ||
<span>Disabled: {itemState.disabled ? 'Y' : 'N'} </span> | ||
<span>Expanded: {itemState.expanded ? 'Y' : 'N'} </span> | ||
<span>Focused: {itemState.focused ? 'Y' : 'N'} </span> | ||
</> | ||
) | ||
}} | ||
</Accordion.Context> | ||
<Index each={items}> | ||
{(item) => ( | ||
<Accordion.Item {...item()}> | ||
<Accordion.ItemTrigger> | ||
What is {item().value}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item().value} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
)} | ||
</Index> | ||
</Accordion.Root> | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/solid/src/components/accordion/examples/context/setValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Accordion } from '@ark-ui/solid/accordion' | ||
import { ChevronDownIcon } from 'lucide-solid' | ||
import { Index } from 'solid-js' | ||
|
||
export const ContextSetValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <button onClick={() => context().setValue(['Vue'])}>Select Vue</button>} | ||
</Accordion.Context> | ||
<Index each={['React', 'Solid', 'Vue']}> | ||
{(item) => ( | ||
<Accordion.Item value={item()}> | ||
<Accordion.ItemTrigger> | ||
What is {item()}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item()} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
)} | ||
</Index> | ||
</Accordion.Root> | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/solid/src/components/accordion/examples/context/value.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Accordion } from '@ark-ui/solid/accordion' | ||
import { ChevronDownIcon } from 'lucide-solid' | ||
import { Index } from 'solid-js' | ||
|
||
export const ContextValue = () => { | ||
return ( | ||
<Accordion.Root defaultValue={['React']}> | ||
<Accordion.Context> | ||
{(context) => <span>Selected items: {context().value.join(', ')}</span>} | ||
</Accordion.Context> | ||
<Index each={['React', 'Solid', 'Vue']}> | ||
{(item) => ( | ||
<Accordion.Item value={item()}> | ||
<Accordion.ItemTrigger> | ||
What is {item()}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{item()} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
)} | ||
</Index> | ||
</Accordion.Root> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/vue/src/components/accordion/examples/context/focusedValue.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { Accordion } from '@ark-ui/vue/accordion' | ||
import { ref } from 'vue' | ||
import { ChevronDownIcon } from '../icons' | ||
const items = ref(['React', 'Solid', 'Vue']) | ||
</script> | ||
|
||
<template> | ||
<Accordion.Root :defaultValue="['React']"> | ||
<Accordion.Context v-slot="context"> | ||
<span>Focused item: {{ context.focusedValue }}</span> | ||
</Accordion.Context> | ||
<Accordion.Item v-for="item in items" :key="item" :value="item"> | ||
<Accordion.ItemTrigger> | ||
What is {{ item }}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{{ item }} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
</template> |
29 changes: 29 additions & 0 deletions
29
packages/vue/src/components/accordion/examples/context/getItemState.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup lang="ts"> | ||
import { Accordion } from '@ark-ui/vue/accordion' | ||
import { ref } from 'vue' | ||
import { ChevronDownIcon } from '../icons' | ||
const items = ref([{ value: 'React' }, { value: 'Solid', disabled: true }, { value: 'Vue' }]) | ||
</script> | ||
|
||
<template> | ||
<Accordion.Root :defaultValue="['React']"> | ||
<Accordion.Context v-slot="context"> | ||
<b>Vue State:</b> | ||
<span>Disabled: {{ context.getItemState(items[2]).disabled ? 'Y' : 'N' }}</span> | ||
<span>Expanded: {{ context.getItemState(items[2]).expanded ? 'Y' : 'N' }}</span> | ||
<span>Focused: {{ context.getItemState(items[2]).focused ? 'Y' : 'N' }}</span> | ||
</Accordion.Context> | ||
<Accordion.Item v-for="item in items" :key="item.value" v-bind="item"> | ||
<Accordion.ItemTrigger> | ||
What is {{ item }}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{{ item }} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
</template> |
26 changes: 26 additions & 0 deletions
26
packages/vue/src/components/accordion/examples/context/setValue.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { Accordion } from '@ark-ui/vue/accordion' | ||
import { ref } from 'vue' | ||
import { ChevronDownIcon } from '../icons' | ||
const items = ref(['React', 'Solid', 'Vue']) | ||
</script> | ||
|
||
<template> | ||
<Accordion.Root :defaultValue="['React']"> | ||
<Accordion.Context v-slot="context"> | ||
<button @click="context.setValue(['Vue'])">Select Vue</button> | ||
</Accordion.Context> | ||
<Accordion.Item v-for="item in items" :key="item" :value="item"> | ||
<Accordion.ItemTrigger> | ||
What is {{ item }}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{{ item }} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
</template> |
26 changes: 26 additions & 0 deletions
26
packages/vue/src/components/accordion/examples/context/value.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { Accordion } from '@ark-ui/vue/accordion' | ||
import { ref } from 'vue' | ||
import { ChevronDownIcon } from '../icons' | ||
const items = ref(['React', 'Solid', 'Vue']) | ||
</script> | ||
|
||
<template> | ||
<Accordion.Root :defaultValue="['React']"> | ||
<Accordion.Context v-slot="context"> | ||
<span>Selected items: {{ context.value.join(', ') }}</span> | ||
</Accordion.Context> | ||
<Accordion.Item v-for="item in items" :key="item" :value="item"> | ||
<Accordion.ItemTrigger> | ||
What is {{ item }}? | ||
<Accordion.ItemIndicator> | ||
<ChevronDownIcon /> | ||
</Accordion.ItemIndicator> | ||
</Accordion.ItemTrigger> | ||
<Accordion.ItemContent> | ||
{{ item }} is a JavaScript library for building user interfaces. | ||
</Accordion.ItemContent> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
</template> |
Oops, something went wrong.