diff --git a/packages/@headlessui-react/README.md b/packages/@headlessui-react/README.md index 7d56343..2f6722a 100644 --- a/packages/@headlessui-react/README.md +++ b/packages/@headlessui-react/README.md @@ -792,14 +792,15 @@ The `Listbox.Button` will automatically open/close the `Listbox.Options` when cl import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds', unavailable: false }, + { id: 2, name: 'Kenton Towne', unavailable: false }, + { id: 3, name: 'Therese Wunsch', unavailable: false }, + { id: 4, name: 'Benedict Kessler', unavailable: true }, + { id: 5, name: 'Katelyn Rohan', unavailable: false }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds', unavailable: false }, - { id: 2, name: 'Kenton Towne', unavailable: false }, - { id: 3, name: 'Therese Wunsch', unavailable: false }, - { id: 4, name: 'Benedict Kessler', unavailable: true }, - { id: 5, name: 'Katelyn Rohan', unavailable: false }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -834,14 +835,15 @@ import { useState, Fragment } from 'react' import { Listbox } from '@headlessui/react' import CheckmarkIcon from './CheckmarkIcon' +const people = [ + { id: 1, name: 'Durward Reynolds' }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds' }, - { id: 2, name: 'Kenton Towne' }, - { id: 3, name: 'Therese Wunsch' }, - { id: 4, name: 'Benedict Kessler' }, - { id: 5, name: 'Katelyn Rohan' }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -849,8 +851,8 @@ function MyListbox() { {selectedPerson.name} {people.map(person => ( - {/* Use the `active` state to conditionally style the active option. */} - {/* Use the `selected` state to conditionally style the selected option. */} + /* Use the `active` state to conditionally style the active option. */ + /* Use the `selected` state to conditionally style the selected option. */ {({ active, selected }) => (
  • @@ -875,14 +877,15 @@ import { useState, Fragment } from 'react' import { Listbox } from '@headlessui/react' import CheckmarkIcon from './CheckmarkIcon' +const people = [ + { id: 1, name: 'Durward Reynolds' }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds' }, - { id: 2, name: 'Kenton Towne' }, - { id: 3, name: 'Therese Wunsch' }, - { id: 4, name: 'Benedict Kessler' }, - { id: 5, name: 'Katelyn Rohan' }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -909,14 +912,15 @@ By default, your `Listbox.Options` instance will be shown/hidden automatically b import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds', unavailable: false }, + { id: 2, name: 'Kenton Towne', unavailable: false }, + { id: 3, name: 'Therese Wunsch', unavailable: false }, + { id: 4, name: 'Benedict Kessler', unavailable: true }, + { id: 5, name: 'Katelyn Rohan', unavailable: false }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds', unavailable: false }, - { id: 2, name: 'Kenton Towne', unavailable: false }, - { id: 3, name: 'Therese Wunsch', unavailable: false }, - { id: 4, name: 'Benedict Kessler', unavailable: true }, - { id: 5, name: 'Katelyn Rohan', unavailable: false }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -942,14 +946,15 @@ If you'd rather handle this yourself (perhaps because you need to add an extra w import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds', unavailable: false }, + { id: 2, name: 'Kenton Towne', unavailable: false }, + { id: 3, name: 'Therese Wunsch', unavailable: false }, + { id: 4, name: 'Benedict Kessler', unavailable: true }, + { id: 5, name: 'Katelyn Rohan', unavailable: false }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds', unavailable: false }, - { id: 2, name: 'Kenton Towne', unavailable: false }, - { id: 3, name: 'Therese Wunsch', unavailable: false }, - { id: 4, name: 'Benedict Kessler', unavailable: true }, - { id: 5, name: 'Katelyn Rohan', unavailable: false }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -984,14 +989,15 @@ Use the `disabled` prop to disable a `Listbox.Option`. This will make it unselec import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds', unavailable: false }, + { id: 2, name: 'Kenton Towne', unavailable: false }, + { id: 3, name: 'Therese Wunsch', unavailable: false }, + { id: 4, name: 'Benedict Kessler', unavailable: true }, + { id: 5, name: 'Katelyn Rohan', unavailable: false }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds', unavailable: false }, - { id: 2, name: 'Kenton Towne', unavailable: false }, - { id: 3, name: 'Therese Wunsch', unavailable: false }, - { id: 4, name: 'Benedict Kessler', unavailable: true }, - { id: 5, name: 'Katelyn Rohan', unavailable: false }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -999,7 +1005,7 @@ function MyListbox() { {selectedPerson.name} {people.map(person => ( - {/* Disabled options will be skipped by keyboard navigation. */} + /* Disabled options will be skipped by keyboard navigation. */ {person.name} @@ -1018,14 +1024,15 @@ To animate the opening/closing of the listbox panel, use the provided `Transitio import { useState } from 'react' import { Listbox, Transition } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds', unavailable: false }, + { id: 2, name: 'Kenton Towne', unavailable: false }, + { id: 3, name: 'Therese Wunsch', unavailable: false }, + { id: 4, name: 'Benedict Kessler', unavailable: true }, + { id: 5, name: 'Katelyn Rohan', unavailable: false }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds', unavailable: false }, - { id: 2, name: 'Kenton Towne', unavailable: false }, - { id: 3, name: 'Therese Wunsch', unavailable: false }, - { id: 4, name: 'Benedict Kessler', unavailable: true }, - { id: 5, name: 'Katelyn Rohan', unavailable: false }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -1070,14 +1077,15 @@ This is easy to change using the `as` prop, which exists on every component. import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds' }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds' }, - { id: 2, name: 'Kenton Towne' }, - { id: 3, name: 'Therese Wunsch' }, - { id: 4, name: 'Benedict Kessler' }, - { id: 5, name: 'Katelyn Rohan' }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -1101,14 +1109,15 @@ To tell an element to render its children directly with no wrapper element, use import { useState, Fragment } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds' }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds' }, - { id: 2, name: 'Kenton Towne' }, - { id: 3, name: 'Therese Wunsch' }, - { id: 4, name: 'Benedict Kessler' }, - { id: 5, name: 'Katelyn Rohan' }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -1134,14 +1143,15 @@ function MyListbox() { import { useState } from 'react' import { Listbox } from '@headlessui/react' +const people = [ + { id: 1, name: 'Durward Reynolds' }, + { id: 2, name: 'Kenton Towne' }, + { id: 3, name: 'Therese Wunsch' }, + { id: 4, name: 'Benedict Kessler' }, + { id: 5, name: 'Katelyn Rohan' }, +] + function MyListbox() { - const people = [ - { id: 1, name: 'Durward Reynolds' }, - { id: 2, name: 'Kenton Towne' }, - { id: 3, name: 'Therese Wunsch' }, - { id: 4, name: 'Benedict Kessler' }, - { id: 5, name: 'Katelyn Rohan' }, - ] const [selectedPerson, setSelectedPerson] = useState(people[0]) return ( @@ -1161,11 +1171,11 @@ function MyListbox() { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `React.Fragment` _(no wrapper element_) | The element or component the `Listbox` should render as. | -| `value` | `T` | | The selected value. | -| `onChange` | `(value: T): void` | | The function to call when a new option is selected. | +| Prop | Type | Default | Description | +| ---------- | ------------------- | --------------------------------------- | -------------------------------------------------------- | +| `as` | String \| Component | `React.Fragment` _(no wrapper element_) | The element or component the `Listbox` should render as. | +| `value` | `T` | | The selected value. | +| `onChange` | `(value: T): void` | | The function to call when a new option is selected. | ##### Render prop object @@ -1240,11 +1250,11 @@ function MyListbox() { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | ----------- | --------------------------------------------------------------------------------------- | -| `as` | String \| Component | `li` | The element or component the `Listbox.Option` should render as. | -| `value` | `T` | | The option value. | -| `disabled` | Boolean | `false` | Whether or not the option should be disabled for keyboard navigation and ARIA purposes. | +| Prop | Type | Default | Description | +| ---------- | ------------------- | ------- | --------------------------------------------------------------------------------------- | +| `as` | String \| Component | `li` | The element or component the `Listbox.Option` should render as. | +| `value` | `T` | | The option value. | +| `disabled` | Boolean | `false` | Whether or not the option should be disabled for keyboard navigation and ARIA purposes. | ##### Render prop object @@ -1279,11 +1289,15 @@ function NotificationsToggle() { Enable notifications ) @@ -1309,10 +1323,14 @@ function NotificationsToggle() { @@ -1333,19 +1351,18 @@ function NotificationsToggle() { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `button` | The element or component the `Switch` should render as. | -| `checked` | Boolean | | Whether or not the switch is checked. | -| `onChange` | `(value: boolean): void` | | The function to call when the switch is toggled. | +| Prop | Type | Default | Description | +| ---------- | ------------------------ | -------- | ------------------------------------------------------- | +| `as` | String \| Component | `button` | The element or component the `Switch` should render as. | +| `checked` | Boolean | | Whether or not the switch is checked. | +| `onChange` | `(value: boolean): void` | | The function to call when the switch is toggled. | ##### Render prop object -| Prop | Type | Description | -| ------ | ------- | ----------------------------------- | +| Prop | Type | Description | +| --------- | ------- | ------------------------------------- | | `checked` | Boolean | Whether or not the switch is checked. | - #### Switch.Label ```jsx @@ -1359,9 +1376,9 @@ function NotificationsToggle() { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `label` | The element or component the `Switch.Label` should render as. | +| Prop | Type | Default | Description | +| ---- | ------------------- | ------- | ------------------------------------------------------------- | +| `as` | String \| Component | `label` | The element or component the `Switch.Label` should render as. | #### Switch.Group @@ -1376,6 +1393,6 @@ function NotificationsToggle() { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `React.Fragment` _(no wrapper element)_| The element or component the `Switch.Group` should render as. | +| Prop | Type | Default | Description | +| ---- | ------------------- | --------------------------------------- | ------------------------------------------------------------- | +| `as` | String \| Component | `React.Fragment` _(no wrapper element)_ | The element or component the `Switch.Group` should render as. | diff --git a/packages/@headlessui-vue/README.md b/packages/@headlessui-vue/README.md index f824cf0..74fef41 100644 --- a/packages/@headlessui-vue/README.md +++ b/packages/@headlessui-vue/README.md @@ -400,7 +400,12 @@ The `ListboxButton` will automatically open/close the `ListboxOptions` when clic {{ selectedPerson.name }} - + {{ person.name }} @@ -434,6 +439,7 @@ export default { { id: 5, name: 'Katelyn Rohan', unavailable: false }, ] const selectedPerson = ref(people[0]) + return { people, selectedPerson, @@ -460,7 +466,13 @@ You can use this state to conditionally apply whatever active/focus styles you l - +
  • {{ person.name }} @@ -499,6 +511,7 @@ export default { { id: 5, name: 'Katelyn Rohan' }, ] const selectedPerson = ref(people[0]) + return { people, selectedPerson, @@ -676,7 +689,12 @@ Use the `disabled` prop to disable a `ListboxOption`. This will make it unselect {{ selectedPerson.name }} - + {{ person.name }} @@ -710,6 +728,7 @@ export default { { id: 5, name: 'Katelyn Rohan', unavailable: false }, ] const selectedPerson = ref(people[0]) + return { people, selectedPerson, @@ -723,8 +742,6 @@ export default { To animate the opening/closing of the menu panel, use Vue's built-in `transition` component. All you need to do is wrap your `ListboxOptions` instance in a `` element and the transition will be applied automatically. - - ```vue ``` @@ -1102,7 +1127,7 @@ Clicking the label will toggle the switch state, like you'd expect from a native @@ -1115,8 +1140,8 @@ Clicking the label will toggle the switch state, like you'd expect from a native ``` @@ -1148,18 +1173,17 @@ export default { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `button` | The element or component the `Switch` should render as. | -| `v-model` | `T` | | The switch value. | +| Prop | Type | Default | Description | +| --------- | ------------------- | -------- | ------------------------------------------------------- | +| `as` | String \| Component | `button` | The element or component the `Switch` should render as. | +| `v-model` | `T` | | The switch value. | ##### Slot props -| Prop | Type | Description | -| ------ | ------- | ----------------------------------- | +| Prop | Type | Description | +| --------- | ------- | ------------------------------------- | | `checked` | Boolean | Whether or not the switch is checked. | - #### SwitchLabel ```html @@ -1173,9 +1197,9 @@ export default { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `label` | The element or component the `SwitchLabel` should render as. | +| Prop | Type | Default | Description | +| ---- | ------------------- | ------- | ------------------------------------------------------------ | +| `as` | String \| Component | `label` | The element or component the `SwitchLabel` should render as. | #### SwitchGroup @@ -1190,6 +1214,6 @@ export default { ##### Props -| Prop | Type | Default | Description | -| ---------- | ----------------------- | --------------------------------------- | -------------------------------------------------------- | -| `as` | String \| Component | `template` _(no wrapper element)_| The element or component the `SwitchGroup` should render as. | +| Prop | Type | Default | Description | +| ---- | ------------------- | --------------------------------- | ------------------------------------------------------------ | +| `as` | String \| Component | `template` _(no wrapper element)_ | The element or component the `SwitchGroup` should render as. |