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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: event handling in machines #789

Merged
merged 45 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8f678c0
refactor: accordion
segunadebayo Aug 13, 2023
d066422
refactor: avatar
segunadebayo Aug 13, 2023
4d056e7
refactor: color picker
segunadebayo Aug 13, 2023
1ad1560
refactor: pagination
segunadebayo Aug 13, 2023
77078f9
refactor: pin input
segunadebayo Aug 13, 2023
cee1090
chore: update scope
segunadebayo Aug 13, 2023
0ce2b9b
refactor: tooltip
segunadebayo Aug 13, 2023
345b6fb
refactor: number input
segunadebayo Aug 13, 2023
d176d6d
fix: website demo
segunadebayo Aug 13, 2023
aac0946
refactor: carousel
segunadebayo Aug 14, 2023
4fa66d3
refactor: checkbox
segunadebayo Aug 14, 2023
adca9ff
refactor: combobox
segunadebayo Aug 14, 2023
f6e1032
refactor: dialog
segunadebayo Aug 14, 2023
b04e22e
refactor: editable
segunadebayo Aug 14, 2023
01271de
refactor: file upload
segunadebayo Aug 14, 2023
519e018
refactor: radio group
segunadebayo Aug 14, 2023
4dadf0d
refactor: presence
segunadebayo Aug 14, 2023
4d1eb2b
refactor: hover card
segunadebayo Aug 14, 2023
7e020dd
refactor: rating group
segunadebayo Aug 14, 2023
1357801
refactor: tabs
segunadebayo Aug 14, 2023
6389a30
refactor: select
segunadebayo Aug 14, 2023
03dc087
refactor: switch
segunadebayo Aug 14, 2023
355333a
docs: update switch
segunadebayo Aug 14, 2023
1bfc657
refactor: slider
segunadebayo Aug 14, 2023
84616ed
fix: switch demos
segunadebayo Aug 14, 2023
541142d
refactor: toast
segunadebayo Aug 14, 2023
4841892
fix: radio group
segunadebayo Aug 14, 2023
8e001a8
refactor: tags input
segunadebayo Aug 14, 2023
768a889
refactor: toggle group
segunadebayo Aug 14, 2023
a5d99f6
refactor: toggle
segunadebayo Aug 14, 2023
6f56d7f
refactor: splitter
segunadebayo Aug 14, 2023
dfd2d3d
refactor: pressable
segunadebayo Aug 14, 2023
68db158
refactor: menu
segunadebayo Aug 14, 2023
5dd9e48
refactor: popover
segunadebayo Aug 14, 2023
21d951f
refactor: range slider
segunadebayo Aug 15, 2023
2a79e15
chore: update typedocs
segunadebayo Aug 15, 2023
19e2bea
refactor: date picker
segunadebayo Aug 15, 2023
e7d43c1
fix: toast types
segunadebayo Aug 15, 2023
50a50d6
fix: style regression
segunadebayo Aug 15, 2023
809c15a
chore: sync imput element on change
segunadebayo Aug 16, 2023
e541829
docs: accordion changes
segunadebayo Aug 16, 2023
c5ae307
refactor: implement focus change
segunadebayo Aug 16, 2023
14a78a2
chore: update range slider
segunadebayo Aug 16, 2023
a38d8e3
chore: update select
segunadebayo Aug 16, 2023
23085e6
chore: update tags input
segunadebayo Aug 16, 2023
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
6 changes: 6 additions & 0 deletions .changeset/hip-papayas-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@zag-js/tags-input": minor
---

- Rename `onHighlight` to `onFocusChange`
- Remove `onTagUpdate`, use `onChange` instead
10 changes: 10 additions & 0 deletions .changeset/hungry-hats-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@zag-js/accordion": minor
---

Remove support for passing value as `string`.

The `value` property must be an array of strings.

- When `multiple` is `false`, the array must contain a single string.
- When `multiple` is `true`, the array can contain multiple strings.
36 changes: 36 additions & 0 deletions .changeset/sixty-files-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"@zag-js/color-picker": minor
"@zag-js/number-input": minor
"@zag-js/range-slider": minor
"@zag-js/rating-group": minor
"@zag-js/toggle-group": minor
"@zag-js/date-picker": minor
"@zag-js/file-upload": minor
"@zag-js/radio-group": minor
"@zag-js/hover-card": minor
"@zag-js/pagination": minor
"@zag-js/tags-input": minor
"@zag-js/dom-query": minor
"@zag-js/accordion": minor
"@zag-js/pin-input": minor
"@zag-js/pressable": minor
"@zag-js/carousel": minor
"@zag-js/checkbox": minor
"@zag-js/combobox": minor
"@zag-js/editable": minor
"@zag-js/presence": minor
"@zag-js/splitter": minor
"@zag-js/popover": minor
"@zag-js/tooltip": minor
"@zag-js/avatar": minor
"@zag-js/dialog": minor
"@zag-js/select": minor
"@zag-js/slider": minor
"@zag-js/switch": minor
"@zag-js/toggle": minor
"@zag-js/toast": minor
"@zag-js/menu": minor
"@zag-js/tabs": minor
---

Refactor machine event handling and rename `PublicApi` to `Api`
14 changes: 7 additions & 7 deletions .xstate/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fetchMachine = createMachine({
},
on: {
"VALUE.SET": {
actions: ["setValue", "invokeOnChange"]
actions: ["setValue"]
}
},
on: {
Expand All @@ -38,23 +38,23 @@ const fetchMachine = createMachine({
focused: {
on: {
"GOTO.NEXT": {
actions: "focusNext"
actions: "focusNextTrigger"
},
"GOTO.PREV": {
actions: "focusPrev"
actions: "focusPrevTrigger"
},
"TRIGGER.CLICK": [{
cond: "isExpanded && canToggle",
actions: ["collapse", "invokeOnChange"]
actions: ["collapse"]
}, {
cond: "!isExpanded",
actions: ["expand", "invokeOnChange"]
actions: ["expand"]
}],
"GOTO.FIRST": {
actions: "focusFirst"
actions: "focusFirstTrigger"
},
"GOTO.LAST": {
actions: "focusLast"
actions: "focusLastTrigger"
},
"TRIGGER.BLUR": {
target: "idle",
Expand Down
6 changes: 3 additions & 3 deletions .xstate/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const fetchMachine = createMachine({
},
on: {
"FILES.SET": {
actions: ["setFilesFromEvent", "invokeOnChange"]
actions: ["setFilesFromEvent"]
},
"FILE.DELETE": {
actions: ["removeFile", "invokeOnChange"]
actions: ["removeFile"]
}
},
on: {
Expand Down Expand Up @@ -55,7 +55,7 @@ const fetchMachine = createMachine({
on: {
"DROPZONE.DROP": {
target: "idle",
actions: ["clearInvalid", "setFilesFromEvent", "invokeOnChange"]
actions: ["clearInvalid", "setFilesFromEvent"]
},
"DROPZONE.DRAG_LEAVE": {
target: "idle",
Expand Down
19 changes: 8 additions & 11 deletions .xstate/number-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const fetchMachine = createMachine({
id: "number-input",
initial: "idle",
context: {
"clampOnBlur": false,
"isInvalidExponential": false,
"clampOnBlur && !isInRange && !isEmptyValue": false,
"isIncrementHint": false,
Expand All @@ -24,12 +23,9 @@ const fetchMachine = createMachine({
},
entry: ["syncInputValue"],
on: {
SET_VALUE: [{
cond: "clampOnBlur",
SET_VALUE: {
actions: ["setValue", "clampValue", "setHintToSet"]
}, {
actions: ["setValue", "setHintToSet"]
}],
},
CLEAR_VALUE: {
actions: ["clearValue"]
},
Expand All @@ -47,17 +43,19 @@ const fetchMachine = createMachine({
},
states: {
idle: {
exit: "invokeOnFocus",
on: {
PRESS_DOWN: {
target: "before:spin",
actions: ["focusInput", "setHint"]
actions: ["focusInput", "invokeOnFocus", "setHint"]
},
PRESS_DOWN_SCRUBBER: {
target: "scrubbing",
actions: ["focusInput", "setHint", "setCursorPoint"]
actions: ["focusInput", "invokeOnFocus", "setHint", "setCursorPoint"]
},
FOCUS: "focused"
FOCUS: {
target: "focused",
actions: ["focusInput", "invokeOnFocus"]
}
}
},
focused: {
Expand Down Expand Up @@ -168,7 +166,6 @@ const fetchMachine = createMachine({
CHANGE_INTERVAL: 50
},
guards: {
"clampOnBlur": ctx => ctx["clampOnBlur"],
"isInvalidExponential": ctx => ctx["isInvalidExponential"],
"clampOnBlur && !isInRange && !isEmptyValue": ctx => ctx["clampOnBlur && !isInRange && !isEmptyValue"],
"isIncrementHint": ctx => ctx["isIncrementHint"],
Expand Down
22 changes: 11 additions & 11 deletions .xstate/pin-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const fetchMachine = createMachine({
on: {
SET_VALUE: [{
cond: "hasIndex",
actions: ["setValueAtIndex", "invokeOnChange"]
actions: ["setValueAtIndex"]
}, {
actions: ["setValue", "invokeOnChange"]
actions: ["setValue"]
}],
CLEAR_VALUE: [{
cond: "isDisabled",
actions: ["clearValue", "invokeOnChange"]
actions: ["clearValue"]
}, {
actions: ["clearValue", "invokeOnChange", "setFocusIndexToFirst"]
actions: ["clearValue", "setFocusIndexToFirst"]
}]
},
on: {
Expand All @@ -56,24 +56,24 @@ const fetchMachine = createMachine({
on: {
INPUT: [{
cond: "isFinalValue && isValidValue",
actions: ["setFocusedValue", "invokeOnChange", "syncInputValue"]
actions: ["setFocusedValue", "syncInputValue"]
}, {
cond: "isValidValue",
actions: ["setFocusedValue", "invokeOnChange", "setNextFocusedIndex", "syncInputValue"]
actions: ["setFocusedValue", "setNextFocusedIndex", "syncInputValue"]
}],
PASTE: [{
cond: "isValidValue",
actions: ["setPastedValue", "invokeOnChange", "setLastValueFocusIndex"]
actions: ["setPastedValue", "setLastValueFocusIndex"]
}, {
actions: ["resetFocusedValue", "invokeOnChange"]
actions: ["revertInputValue"]
}],
BLUR: {
target: "idle",
actions: "clearFocusedIndex"
},
DELETE: {
cond: "hasValue",
actions: ["clearFocusedValue", "invokeOnChange"]
actions: ["clearFocusedValue"]
},
ARROW_LEFT: {
actions: "setPrevFocusedIndex"
Expand All @@ -83,9 +83,9 @@ const fetchMachine = createMachine({
},
BACKSPACE: [{
cond: "hasValue",
actions: ["clearFocusedValue", "invokeOnChange"]
actions: ["clearFocusedValue"]
}, {
actions: ["setPrevFocusedIndex", "clearFocusedValue", "invokeOnChange"]
actions: ["setPrevFocusedIndex", "clearFocusedValue"]
}],
ENTER: {
cond: "isValueComplete",
Expand Down
6 changes: 3 additions & 3 deletions .xstate/range-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fetchMachine = createMachine({
"isVertical": false,
"isVertical": false
},
entry: ["checkValue"],
entry: ["coarseValue"],
activities: ["trackFormControlState", "trackThumbsSize"],
on: {
SET_VALUE: [{
Expand Down Expand Up @@ -49,7 +49,7 @@ const fetchMachine = createMachine({
},
FOCUS: {
target: "focus",
actions: "setActiveIndex"
actions: "setFocusedIndex"
}
}
},
Expand Down Expand Up @@ -90,7 +90,7 @@ const fetchMachine = createMachine({
},
BLUR: {
target: "idle",
actions: "clearActiveIndex"
actions: "clearFocusedIndex"
}
}
},
Expand Down
51 changes: 25 additions & 26 deletions .xstate/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ const fetchMachine = createMachine({
initial: "idle",
on: {
HIGHLIGHT_OPTION: {
actions: ["setHighlightedOption", "invokeOnHighlight"]
actions: ["setHighlightedOption"]
},
SELECT_OPTION: {
actions: ["setSelectedOption", "invokeOnSelect"]
actions: ["setSelectedOption"]
},
CLEAR_SELECTED: {
actions: ["clearSelectedOption", "invokeOnSelect"]
actions: ["clearSelectedOption"]
}
},
entry: ["setInitialSelectedOption"],
activities: ["trackFormControlState"],
on: {
UPDATE_CONTEXT: {
Expand Down Expand Up @@ -70,32 +69,32 @@ const fetchMachine = createMachine({
},
ARROW_UP: {
target: "open",
actions: ["highlightLastOption", "invokeOnHighlight"]
actions: ["highlightLastOption"]
},
ARROW_DOWN: {
target: "open",
actions: ["highlightFirstOption", "invokeOnHighlight"]
actions: ["highlightFirstOption"]
},
ARROW_LEFT: [{
cond: "hasSelectedOption",
actions: ["selectPreviousOption", "invokeOnSelect"]
actions: ["selectPreviousOption"]
}, {
actions: ["selectLastOption", "invokeOnSelect"]
actions: ["selectLastOption"]
}],
ARROW_RIGHT: [{
cond: "hasSelectedOption",
actions: ["selectNextOption", "invokeOnSelect"]
actions: ["selectNextOption"]
}, {
actions: ["selectFirstOption", "invokeOnSelect"]
actions: ["selectFirstOption"]
}],
HOME: {
actions: ["selectFirstOption", "invokeOnSelect"]
actions: ["selectFirstOption"]
},
END: {
actions: ["selectLastOption", "invokeOnSelect"]
actions: ["selectLastOption"]
},
TYPEAHEAD: {
actions: ["selectMatchingOption", "invokeOnSelect"]
actions: ["selectMatchingOption"]
},
OPEN: {
target: "open"
Expand All @@ -118,52 +117,52 @@ const fetchMachine = createMachine({
},
OPTION_CLICK: [{
target: "focused",
actions: ["selectHighlightedOption", "invokeOnSelect", "invokeOnClose"],
actions: ["selectHighlightedOption", "invokeOnClose"],
cond: "closeOnSelect"
}, {
actions: ["selectHighlightedOption", "invokeOnSelect"]
actions: ["selectHighlightedOption"]
}],
TRIGGER_KEY: [{
target: "focused",
actions: ["selectHighlightedOption", "invokeOnSelect", "invokeOnClose"],
actions: ["selectHighlightedOption", "invokeOnClose"],
cond: "closeOnSelect"
}, {
actions: ["selectHighlightedOption", "invokeOnSelect"]
actions: ["selectHighlightedOption"]
}],
BLUR: {
target: "focused",
actions: ["invokeOnClose"]
},
HOME: {
actions: ["highlightFirstOption", "invokeOnHighlight"]
actions: ["highlightFirstOption"]
},
END: {
actions: ["highlightLastOption", "invokeOnHighlight"]
actions: ["highlightLastOption"]
},
ARROW_DOWN: [{
cond: "hasHighlightedOption",
actions: ["highlightNextOption", "invokeOnHighlight"]
actions: ["highlightNextOption"]
}, {
actions: ["highlightFirstOption", "invokeOnHighlight"]
actions: ["highlightFirstOption"]
}],
ARROW_UP: [{
cond: "hasHighlightedOption",
actions: ["highlightPreviousOption", "invokeOnHighlight"]
actions: ["highlightPreviousOption"]
}, {
actions: ["highlightLastOption", "invokeOnHighlight"]
actions: ["highlightLastOption"]
}],
TYPEAHEAD: {
actions: ["highlightMatchingOption", "invokeOnHighlight"]
actions: ["highlightMatchingOption"]
},
POINTER_MOVE: {
actions: ["highlightOption", "invokeOnHighlight"]
actions: ["highlightOption"]
},
POINTER_LEAVE: {
actions: ["clearHighlightedOption"]
},
TAB: [{
target: "idle",
actions: ["selectHighlightedOption", "invokeOnClose", "invokeOnSelect", "clearHighlightedOption"],
actions: ["selectHighlightedOption", "invokeOnClose", "clearHighlightedOption"],
cond: "selectOnTab"
}, {
target: "idle",
Expand Down
Loading
Loading