Skip to content

Commit

Permalink
refactor: consistent boolean (#1435)
Browse files Browse the repository at this point in the history
* refactor: accordion

* refactor: avatar

* refactor: carousel

* refactor: checkbox

* refactor: checkbox

* refactor: clipboard

* refactor: collapsible

* refactor: color picker

* refactor: combobox

* refactor: treeview

* refactor: tabs

* refactor: signature pad

* refactor: editable

* refactor: floating panel

* refactor: file upload

* refactor: machines

* refactor: update examples

* fix: types

* fix: checkbox

* refactor: cleanup toasts

* chore: update tag

* refactor: color picker

* refactor: set open

* chore: js doc

* refactor: one less package

* chore: update

* refactor: toast api

* chore: update

* feat: add readonly

* fix: props

* docs: update
  • Loading branch information
segunadebayo committed Apr 22, 2024
1 parent 037ccfb commit 23ed828
Show file tree
Hide file tree
Showing 225 changed files with 1,803 additions and 1,893 deletions.
10 changes: 10 additions & 0 deletions .changeset/cyan-parrots-grin.md
@@ -0,0 +1,10 @@
---
"@zag-js/checkbox": minor
---

Rename `api` properties

- `isChecked` to `checked`
- `isDisabled` to `disabled`
- `isIndeterminate` to `indeterminate`
- `isFocused` to `focused`
6 changes: 6 additions & 0 deletions .changeset/friendly-rings-impress.md
@@ -0,0 +1,6 @@
---
"@zag-js/avatar": minor
---

- Rename `api.isLoaded` to `api.loaded`
- Remove `api.showFallback` since it's equivalent to `!api.loaded`
7 changes: 7 additions & 0 deletions .changeset/gold-pigs-smash.md
@@ -0,0 +1,7 @@
---
"@zag-js/radio-group": minor
"@zag-js/checkbox": minor
"@zag-js/switch": minor
---

Add support for `readOnly` prop
8 changes: 8 additions & 0 deletions .changeset/large-weeks-shout.md
@@ -0,0 +1,8 @@
---
"@zag-js/editable": minor
---

Rename `api` properties

- `isEditing` -> `editing`
- `isValueEmpty` -> `empty`
13 changes: 13 additions & 0 deletions .changeset/plenty-cherries-lay.md
@@ -0,0 +1,13 @@
---
"@zag-js/tree-view": minor
---

- Rename `api.getItemState` properties

- `isDisabled` -> `disabled`
- `isFocused` -> `focused`
- `isSelected` -> `selected`

- Rename `api.getBranchState` properties

- `isExpanded` -> `expanded`
10 changes: 10 additions & 0 deletions .changeset/polite-vans-nail.md
@@ -0,0 +1,10 @@
---
"@zag-js/combobox": minor
---

Rename `api` properties

- `isFocused` -> `focused`
- `isOpen` -> `open`
- `isInputValueEmpty` -> `inputEmpty`
- `open()`, `close()` -> `setOpen(true|false)`
8 changes: 8 additions & 0 deletions .changeset/quick-flowers-sparkle.md
@@ -0,0 +1,8 @@
---
"@zag-js/signature-pad": minor
---

Rename `api` properties

- `isDrawing` -> `drawing`
- `isEmpty` -> `empty`
10 changes: 10 additions & 0 deletions .changeset/real-icons-study.md
@@ -0,0 +1,10 @@
---
"@zag-js/collapsible": minor
---

Rename `api` properties

- `isVisible` -> `visible`
- `isDisabled` -> `disabled`
- `isOpen` -> `open`
- `open`, `close` -> `setOpen(true|false)`
9 changes: 9 additions & 0 deletions .changeset/sour-boxes-march.md
@@ -0,0 +1,9 @@
---
"@zag-js/file-upload": minor
---

Rename `api` properties

- `isDragging` -> `dragging`
- `isFocused` -> `focused`
- `open()` -> `openFilePicker()`
12 changes: 12 additions & 0 deletions .changeset/swift-hornets-hug.md
@@ -0,0 +1,12 @@
---
"@zag-js/carousel": minor
---

- Rename `api.getItemState` properties

- `isCurrent` to `current`
- `isNext` to `next`
- `isPrevious` to `previous`
- `isInView` to `inView`

- Rename `api.isAutoPlay` to `api.autoPlaying`
9 changes: 9 additions & 0 deletions .changeset/swift-years-do.md
@@ -0,0 +1,9 @@
---
"@zag-js/color-picker": minor
---

Rename `api` properties

- `isDragging` -> `dragging`
- `isOpen` -> `open`
- `open()`, `close()` -> `setOpen(true|false)`
5 changes: 5 additions & 0 deletions .changeset/three-planes-mix.md
@@ -0,0 +1,5 @@
---
"@zag-js/clipboard": minor
---

Rename `api.isCopied` to `api.copied`
9 changes: 9 additions & 0 deletions .changeset/unlucky-pumpkins-impress.md
@@ -0,0 +1,9 @@
---
"@zag-js/tabs": minor
---

Rename `api.getTriggerState` properties

- `isSelected` -> `selected`
- `isDisabled` -> `disabled`
- `isFocused` -> `focused`
8 changes: 8 additions & 0 deletions .changeset/witty-tomatoes-roll.md
@@ -0,0 +1,8 @@
---
"@zag-js/accordion": minor
---

- Rename `getItemState` properties
- `isOpen` -> `expanded`
- `isDisabled` -> `disabled`
- `isFocused` -> `focused`
2 changes: 1 addition & 1 deletion .xstate/toggle-group.js
Expand Up @@ -15,7 +15,7 @@ const fetchMachine = createMachine({
context: {
"!(isClickFocus && isTabbingBackward)": false
},
entry: ["checkFocusableToggles", "checkIfWithinToolbar"],
entry: ["checkIfWithinToolbar"],
on: {
"VALUE.SET": {
actions: ["setValue"]
Expand Down
2 changes: 1 addition & 1 deletion examples/next-ts/components/dialog.tsx
Expand Up @@ -28,7 +28,7 @@ export function Dialog(props: Props) {
return (
<>
<button {...api.triggerProps}>Open Dialog</button>
{api.isOpen && (
{api.open && (
<Portal>
<div {...api.backdropProps} />
<div {...api.positionerProps}>
Expand Down
1 change: 0 additions & 1 deletion examples/next-ts/package.json
Expand Up @@ -80,7 +80,6 @@
"@zag-js/tree-view": "workspace:*",
"@zag-js/types": "workspace:*",
"@zag-js/utils": "workspace:*",
"@zag-js/visually-hidden": "workspace:*",
"form-serialize": "0.7.2",
"lucide-react": "0.372.0",
"match-sorter": "6.3.4",
Expand Down
6 changes: 3 additions & 3 deletions examples/next-ts/pages/checkbox.tsx
Expand Up @@ -34,15 +34,15 @@ export default function Page() {
<fieldset>
<label {...api.rootProps}>
<div {...api.controlProps} />
<span {...api.labelProps}>Input {api.isChecked ? "Checked" : "Unchecked"}</span>
<span {...api.labelProps}>Input {api.checked ? "Checked" : "Unchecked"}</span>
<input {...api.hiddenInputProps} data-testid="hidden-input" />
<div {...api.indicatorProps}>Indicator</div>
</label>

<button type="button" disabled={api.isChecked} onClick={() => api.setChecked(true)}>
<button type="button" disabled={api.checked} onClick={() => api.setChecked(true)}>
Check
</button>
<button type="button" disabled={!api.isChecked} onClick={() => api.setChecked(false)}>
<button type="button" disabled={!api.checked} onClick={() => api.setChecked(false)}>
Uncheck
</button>
<button type="reset">Reset Form</button>
Expand Down
2 changes: 1 addition & 1 deletion examples/next-ts/pages/clipboard.tsx
Expand Up @@ -29,7 +29,7 @@ export default function Page() {
<label {...api.labelProps}>Copy this link</label>
<div {...api.controlProps}>
<input {...api.inputProps} />
<button {...api.triggerProps}>{api.isCopied ? <ClipboardCheck /> : <ClipboardCopyIcon />}</button>
<button {...api.triggerProps}>{api.copied ? <ClipboardCheck /> : <ClipboardCopyIcon />}</button>
</div>
<div {...api.getIndicatorProps({ copied: true })}>Copied!</div>
<div {...api.getIndicatorProps({ copied: false })}>Copy</div>
Expand Down
8 changes: 4 additions & 4 deletions examples/next-ts/pages/cmdk.tsx
Expand Up @@ -102,14 +102,14 @@ export default function Page() {

useEffect(() => {
const fn = (event: KeyboardEvent) => {
if (dialogApi.isOpen) return
if (dialogApi.open) return

const isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator?.platform)
const hotkey = isMac ? "metaKey" : "ctrlKey"

if (event.key?.toLowerCase() === "k" && event[hotkey]) {
event.preventDefault()
dialogApi.open()
dialogApi.setOpen(true)
}
}
document.addEventListener("keydown", fn, true)
Expand All @@ -129,7 +129,7 @@ export default function Page() {
or press <kbd> Cmd+K</kbd>
</div>

{dialogApi.isOpen && (
{dialogApi.open && (
<Portal>
<div {...dialogApi.backdropProps} />
<div {...dialogApi.positionerProps}>
Expand All @@ -139,7 +139,7 @@ export default function Page() {
collection={collection}
onValueChange={({ value }) => {
console.log("Selected value:", value)
queueMicrotask(() => dialogApi.close())
queueMicrotask(() => dialogApi.setOpen(false))
}}
onInputValueChange={({ inputValue }) => {
setInputValue(inputValue)
Expand Down
4 changes: 2 additions & 2 deletions examples/next-ts/pages/collapsible.tsx
Expand Up @@ -38,8 +38,8 @@ export default function Page() {

<div>
<div>Toggle Controls</div>
<button onClick={api.open}>Open</button>
<button onClick={api.close}>Close</button>
<button onClick={() => api.setOpen(true)}>Open</button>
<button onClick={() => api.setOpen(false)}>Close</button>
</div>
</main>

Expand Down
8 changes: 4 additions & 4 deletions examples/next-ts/pages/combo-textarea.tsx
Expand Up @@ -96,21 +96,21 @@ export default function Page() {
api.reposition()
},
onPointerDown() {
api.close()
api.setOpen(true)
},
onKeyDown(event) {
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
api.close()
api.setOpen(false)
}
},
onChange(event) {
const trigger = getTrigger(event.currentTarget)
const searchValue = getSearchValue(event.currentTarget)

if (trigger) {
api.open()
api.setOpen(true)
} else if (!searchValue) {
api.close()
api.setOpen(false)
}

setSearchValue(searchValue)
Expand Down
4 changes: 2 additions & 2 deletions examples/next-ts/pages/dialog/controlled.tsx
Expand Up @@ -23,8 +23,8 @@ export default function Dialog() {
<div>
<button onClick={() => setOpen(!isOpen)}>Open Dialog</button>
<p>state - isOpen: {String(isOpen)}</p>
<p>machine - isOpen: {String(api.isOpen)}</p>
{api.isOpen && (
<p>machine - isOpen: {String(api.open)}</p>
{api.open && (
<Portal>
<div {...api.backdropProps} />
<div {...api.positionerProps}>
Expand Down
6 changes: 3 additions & 3 deletions examples/next-ts/pages/dialog/index.tsx
Expand Up @@ -33,7 +33,7 @@ export default function Page() {

<div style={{ minHeight: "1200px" }} />

{parentDialog.isOpen && (
{parentDialog.open && (
<Portal>
<div {...parentDialog.backdropProps} />
<div data-testid="positioner-1" {...parentDialog.positionerProps}>
Expand All @@ -52,7 +52,7 @@ export default function Page() {
Open Nested
</button>

{childDialog.isOpen && (
{childDialog.open && (
<Portal>
<div {...childDialog.backdropProps} />
<div data-testid="positioner-2" {...childDialog.positionerProps}>
Expand All @@ -61,7 +61,7 @@ export default function Page() {
<button {...childDialog.closeTriggerProps} data-testid="close-2">
X
</button>
<button onClick={() => parentDialog.close()} data-testid="special-close">
<button onClick={() => parentDialog.setOpen(false)} data-testid="special-close">
Close Dialog 1
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion examples/next-ts/pages/dialog/overflow.tsx
Expand Up @@ -9,7 +9,7 @@ export default function Dialog() {
<div>
<div style={{ width: "200vw", height: "30vh" }} />
<button {...api.triggerProps}> Click me</button>
{api.isOpen && (
{api.open && (
<Portal>
<div {...api.backdropProps} />
<div {...api.positionerProps}>
Expand Down
4 changes: 2 additions & 2 deletions examples/next-ts/pages/editable.tsx
Expand Up @@ -29,12 +29,12 @@ export default function Page() {
<span data-testid="preview" {...api.previewProps} />
</div>
<div {...api.controlProps}>
{!api.isEditing && (
{!api.editing && (
<button data-testid="edit-button" {...api.editTriggerProps}>
Edit
</button>
)}
{api.isEditing && (
{api.editing && (
<>
<button data-testid="save-button" {...api.submitTriggerProps}>
Save
Expand Down
2 changes: 1 addition & 1 deletion examples/next-ts/pages/hover-card.tsx
Expand Up @@ -29,7 +29,7 @@ export default function Page() {
Twitter
</a>

{api.isOpen && (
{api.open && (
<Portal>
<div {...api.positionerProps}>
<div {...api.contentProps}>
Expand Down
9 changes: 2 additions & 7 deletions examples/next-ts/pages/pagination.tsx
@@ -1,7 +1,6 @@
import * as pagination from "@zag-js/pagination"
import { normalizeProps, useMachine } from "@zag-js/react"
import { paginationControls, paginationData } from "@zag-js/shared"
import { visuallyHiddenStyle } from "@zag-js/visually-hidden"
import { useId, useState } from "react"
import { Print } from "../components/print"
import { StateVisualizer } from "../components/state-visualizer"
Expand Down Expand Up @@ -60,9 +59,7 @@ export default function Page() {
<nav {...api.rootProps}>
<ul>
<li>
<button {...api.prevTriggerProps}>
Previous <span style={visuallyHiddenStyle}>Page</span>
</button>
<button {...api.prevTriggerProps}>Previous</button>
</li>
{api.pages.map((page, i) => {
if (page.type === "page")
Expand All @@ -81,9 +78,7 @@ export default function Page() {
)
})}
<li>
<button {...api.nextTriggerProps}>
Next <span style={visuallyHiddenStyle}>Page</span>
</button>
<button {...api.nextTriggerProps}>Next</button>
</li>
</ul>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/next-ts/pages/popover-selection.tsx
Expand Up @@ -53,14 +53,14 @@ export default function Page() {
const onMouseUp = () => {
if (!hasSelectionWithin(node)) return
api.reposition()
api.open()
api.setOpen(true)
}

const onSelect = () => {
if (hasSelectionWithin(node)) {
return api.reposition()
}
api.close()
api.setOpen(false)
}

doc.addEventListener("mouseup", onMouseUp)
Expand Down
2 changes: 1 addition & 1 deletion examples/next-ts/pages/presence.tsx
Expand Up @@ -17,7 +17,7 @@ export default function Page() {
return (
<main className="presence">
<button onClick={() => setPresent((c) => !c)}>Toggle</button>
{api.isPresent && (
{api.present && (
<div
ref={(node) => {
api.setNode(node)
Expand Down

0 comments on commit 23ed828

Please sign in to comment.