Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consistent boolean #1435

Merged
merged 31 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bcad01c
refactor: accordion
segunadebayo Apr 21, 2024
79bb3c4
refactor: avatar
segunadebayo Apr 21, 2024
bd23cb2
refactor: carousel
segunadebayo Apr 21, 2024
19a01dc
refactor: checkbox
segunadebayo Apr 21, 2024
3943536
refactor: checkbox
segunadebayo Apr 21, 2024
d9bc183
refactor: clipboard
segunadebayo Apr 21, 2024
54686db
refactor: collapsible
segunadebayo Apr 21, 2024
ac0eaac
refactor: color picker
segunadebayo Apr 21, 2024
9c29223
refactor: combobox
segunadebayo Apr 21, 2024
18b9019
refactor: treeview
segunadebayo Apr 21, 2024
90f916a
refactor: tabs
segunadebayo Apr 21, 2024
cc4f7b1
refactor: signature pad
segunadebayo Apr 21, 2024
fa373b6
refactor: editable
segunadebayo Apr 21, 2024
fe271ef
refactor: floating panel
segunadebayo Apr 21, 2024
799b0a0
refactor: file upload
segunadebayo Apr 21, 2024
e45d319
refactor: machines
segunadebayo Apr 21, 2024
3ef52b5
refactor: update examples
segunadebayo Apr 21, 2024
e80e8ef
fix: types
segunadebayo Apr 22, 2024
8560a1f
fix: checkbox
segunadebayo Apr 22, 2024
37e6599
refactor: cleanup toasts
segunadebayo Apr 22, 2024
baa030b
chore: update tag
segunadebayo Apr 22, 2024
594df98
refactor: color picker
segunadebayo Apr 22, 2024
7183f73
refactor: set open
segunadebayo Apr 22, 2024
af721f9
chore: js doc
segunadebayo Apr 22, 2024
1806f21
refactor: one less package
segunadebayo Apr 22, 2024
0968c17
chore: update
segunadebayo Apr 22, 2024
d5c2eb4
refactor: toast api
segunadebayo Apr 22, 2024
b2ce6ff
chore: update
segunadebayo Apr 22, 2024
4cf266a
feat: add readonly
segunadebayo Apr 22, 2024
733f802
fix: props
segunadebayo Apr 22, 2024
ae65ba3
docs: update
segunadebayo Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/cyan-parrots-grin.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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