Skip to content

docs: update playground #2404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions website/components/machines/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ const items = [
},
]

type AccordionProps = {
controls: {
collapsible: boolean
multiple: boolean
}
}

export function Accordion(props: AccordionProps) {
export function Accordion(props: Omit<accordion.Props, "id">) {
const service = useMachine(accordion.machine, {
id: useId(),
defaultValue: ["Aircraft"],
...props.controls,
...props,
})

const api = accordion.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/angle-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as angleSlider from "@zag-js/angle-slider"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

export function AngleSlider(props: any) {
export function AngleSlider(props: Omit<angleSlider.Props, "id">) {
const service = useMachine(angleSlider.machine, {
id: useId(),
...props.controls,
...props,
})

const api = angleSlider.connect(service, normalizeProps)
Expand Down
8 changes: 5 additions & 3 deletions website/components/machines/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as avatar from "@zag-js/avatar"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

export function Avatar(props: { controls: { src: string; name: string } }) {
const { src, name } = props.controls
export function Avatar(
props: Omit<avatar.Props, "id"> & { src: string; name: string },
) {
const { src, name } = props

const service = useMachine(avatar.machine, {
id: useId(),
...props.controls,
...props,
})

const api = avatar.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const items = [
"https://tinyurl.com/yp4rfum7",
]

export function Carousel(props: any) {
export function Carousel(props: Omit<carousel.Props, "id" | "slideCount">) {
const service = useMachine(carousel.machine, {
id: useId(),
slideCount: items.length,
...props.controls,
...props,
})

const api = carousel.connect(service, normalizeProps)
Expand Down
15 changes: 5 additions & 10 deletions website/components/machines/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@ import * as checkbox from "@zag-js/checkbox"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId, useState } from "react"

type CheckboxProps = {
controls: {
disabled: boolean
indeterminate: boolean
}
}

export function Checkbox(props: CheckboxProps) {
const { disabled, indeterminate } = props.controls
export function Checkbox(
props: Omit<checkbox.Props, "id"> & { indeterminate: boolean },
) {
const { indeterminate } = props
const [checked, setChecked] = useState<boolean | "indeterminate">(
indeterminate ? "indeterminate" : false,
)

const service = useMachine(checkbox.machine, {
id: useId(),
disabled,
checked: indeterminate ? "indeterminate" : checked,
onCheckedChange(details) {
setChecked(details.checked)
},
...props,
})

const api = checkbox.connect(service, normalizeProps)
Expand Down
11 changes: 2 additions & 9 deletions website/components/machines/clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"
import { HiCheck, HiOutlineClipboard } from "react-icons/hi"

type Props = {
controls: {
value: string
timeout: number
}
}

export function Clipboard(props: Props) {
export function Clipboard(props: Omit<clipboard.Props, "id">) {
const service = useMachine(clipboard.machine, {
id: useId(),
...props.controls,
...props,
})

const api = clipboard.connect(service, normalizeProps)
Expand Down
11 changes: 2 additions & 9 deletions website/components/machines/collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import * as collapsible from "@zag-js/collapsible"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

type CollapsibleProps = {
controls: {
disabled: boolean
dir: "ltr" | "rtl"
}
}

export function Collapsible(props: CollapsibleProps) {
export function Collapsible(props: Omit<collapsible.Props, "id">) {
const service = useMachine(collapsible.machine, {
id: useId(),
...props.controls,
...props,
})

const api = collapsible.connect(service, normalizeProps)
Expand Down
14 changes: 2 additions & 12 deletions website/components/machines/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import * as colorPicker from "@zag-js/color-picker"
import { Portal, normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

type Props = {
controls: {
disabled: boolean
readOnly: boolean
closeOnSelect: boolean
format: "rgba" | "hsla" | "hsba"
}
}

const presets = ["#f47373", "#697689", "#38a169", "#3182ce"]

const Show = (props: { when: boolean; children: React.ReactNode }) => {
Expand All @@ -32,12 +23,11 @@ const EyeDropIcon = () => (
</svg>
)

export function ColorPicker(props: Props) {
export function ColorPicker(props: Omit<colorPicker.Props, "id">) {
const service = useMachine(colorPicker.machine, {
id: useId(),
defaultValue: colorPicker.parse("#38a169").toFormat("hsla"),
...props.controls,
format: "hsla",
...props,
})

const api = colorPicker.connect(service, normalizeProps)
Expand Down
13 changes: 2 additions & 11 deletions website/components/machines/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ import { Portal, mergeProps, normalizeProps, useMachine } from "@zag-js/react"
import { useId, useMemo, useState } from "react"
import { createFilter } from "@zag-js/i18n-utils"

interface ComboboxProps {
controls: {
disabled: boolean
readOnly: boolean
blurOnSelect: boolean
loop: boolean
}
}

const comboboxData = [
{ label: "Zambia", code: "ZA" },
{ label: "Benin", code: "BN" },
Expand Down Expand Up @@ -58,7 +49,7 @@ const CaretIcon = () => (
</svg>
)

export function Combobox(props: ComboboxProps) {
export function Combobox(props: Omit<combobox.Props, "id">) {
const [options, setOptions] = useState(comboboxData)

const filter = createFilter({ sensitivity: "base" })
Expand All @@ -83,7 +74,7 @@ export function Combobox(props: ComboboxProps) {
setOptions(filtered.length > 0 ? filtered : comboboxData)
},
placeholder: "Type or select country",
...props.controls,
...props,
})

const api = combobox.connect(service, normalizeProps)
Expand Down
8 changes: 2 additions & 6 deletions website/components/machines/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ const data = [
{ label: "Duplicate", value: "duplicate" },
]

type ContextMenuProps = {
controls: {}
}

export function ContextMenu(props: ContextMenuProps) {
export function ContextMenu(props: Omit<menu.Props, "id">) {
const service = useMachine(menu.machine, {
id: useId(),
...props.controls,
...props,
})

const api = menu.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"
import { BiCalendar, BiChevronLeft, BiChevronRight } from "react-icons/bi"

export function DatePicker(props: any) {
export function DatePicker(props: Omit<datePicker.Props, "id">) {
const service = useMachine(datePicker.machine, {
id: useId(),
locale: "en-US",
selectionMode: "single",
...props.controls,
...props,
})

const api = datePicker.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { normalizeProps, useMachine, Portal } from "@zag-js/react"
import { HiX } from "react-icons/hi"
import { useId } from "react"

export function Dialog(props: { controls: any }) {
export function Dialog(props: Omit<dialog.Props, "id">) {
const service = useMachine(dialog.machine, {
id: useId(),
...props.controls,
...props,
})

const api = dialog.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as editable from "@zag-js/editable"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

export function Editable(props: any) {
export function Editable(props: Omit<editable.Props, "id">) {
const service = useMachine(editable.machine, {
id: useId(),
...props.controls,
...props,
})

const api = editable.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/file-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"
import { HiX } from "react-icons/hi"

export function FileUpload(props: { controls: any }) {
export function FileUpload(props: Omit<fileUpload.Props, "id">) {
const service = useMachine(fileUpload.machine, {
id: useId(),
...props.controls,
...props,
})

const api = fileUpload.connect(service, normalizeProps)
Expand Down
11 changes: 2 additions & 9 deletions website/components/machines/hover-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import * as hoverCard from "@zag-js/hover-card"
import { normalizeProps, useMachine, Portal } from "@zag-js/react"
import { useId } from "react"

type HoverCardProps = {
controls: {
openDelay: number
closeDelay: number
}
}

export function HoverCard(props: HoverCardProps) {
export function HoverCard(props: Omit<hoverCard.Props, "id">) {
const service = useMachine(hoverCard.machine, {
id: useId(),
...props.controls,
...props,
})

const api = hoverCard.connect(service, normalizeProps)
Expand Down
6 changes: 3 additions & 3 deletions website/components/machines/listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Item {
favorite?: boolean
}

export function Listbox(props: ListboxProps) {
export function Listbox(props: Omit<listbox.Props<Item>, "id" | "collection">) {
const collection = listbox.collection({
items: people,
itemToValue: (item) => item.username,
Expand All @@ -27,9 +27,9 @@ export function Listbox(props: ListboxProps) {
})

const service = useMachine(listbox.machine as listbox.Machine<Item>, {
collection,
id: useId(),
...props.controls,
collection,
...props,
})

const api = listbox.connect(service, normalizeProps)
Expand Down
8 changes: 2 additions & 6 deletions website/components/machines/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ const data = [
{ label: "Duplicate", value: "duplicate" },
]

type MenuProps = {
controls: {}
}

export function Menu(props: MenuProps) {
export function Menu(props: Omit<menu.Props, "id">) {
const service = useMachine(menu.machine, {
id: useId(),
...props.controls,
...props,
})

const api = menu.connect(service, normalizeProps)
Expand Down
3 changes: 2 additions & 1 deletion website/components/machines/nested-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const shareMenuData = [
{ label: "WhatsApp", value: "whatsapp" },
]

export function NestedMenu() {
export function NestedMenu(props: Omit<menu.Props, "id">) {
// Level 1 - File Menu
const fileMenuService = useMachine(menu.machine, {
id: "1",
"aria-label": "File",
...props,
})

const fileMenu = menu.connect(fileMenuService, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/number-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { normalizeProps, useMachine } from "@zag-js/react"
import { BiChevronDown, BiChevronUp } from "react-icons/bi"
import { useId } from "react"

export function NumberInput(props: any) {
export function NumberInput(props: Omit<numberInput.Props, "id">) {
const service = useMachine(numberInput.machine, {
id: useId(),
...props.controls,
...props,
})

const api = numberInput.connect(service, normalizeProps)
Expand Down
11 changes: 2 additions & 9 deletions website/components/machines/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import * as pagination from "@zag-js/pagination"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

type PaginationProps = {
controls: {
pageSize: number
siblingCount: number
}
}

export function Pagination(props: PaginationProps) {
export function Pagination(props: Omit<pagination.Props, "id">) {
const service = useMachine(pagination.machine, {
id: useId(),
count: 1000,
...props.controls,
...props,
})

const api = pagination.connect(service, normalizeProps)
Expand Down
4 changes: 2 additions & 2 deletions website/components/machines/pin-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as pinInput from "@zag-js/pin-input"
import { normalizeProps, useMachine } from "@zag-js/react"
import { useId } from "react"

export function PinInput(props: any) {
export function PinInput(props: Omit<pinInput.Props, "id">) {
const service = useMachine(pinInput.machine, {
id: useId(),
...props.controls,
...props,
})

const api = pinInput.connect(service, normalizeProps)
Expand Down
Loading