Gathering detailed insights and metrics for @zag-js/core
Gathering detailed insights and metrics for @zag-js/core
Gathering detailed insights and metrics for @zag-js/core
Gathering detailed insights and metrics for @zag-js/core
Build your design system in React, Solid, Vue or Svelte. Powered by finite state machines
npm install @zag-js/core
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
98.7
Quality
95.4
Maintenance
100
Vulnerability
100
License
@zag-js/tour@1.18.0
Updated on Jun 30, 2025
@zag-js/toggle@1.18.0
Updated on Jun 30, 2025
@zag-js/aria-hidden@1.18.0
Updated on Jun 30, 2025
@zag-js/tree-view@1.18.0
Updated on Jun 30, 2025
@zag-js/auto-resize@1.18.0
Updated on Jun 30, 2025
@zag-js/collection@1.18.0
Updated on Jun 30, 2025
TypeScript (84.57%)
MDX (11.59%)
CSS (2.68%)
JavaScript (0.95%)
Handlebars (0.21%)
Total Downloads
14,791,552
Last Day
22,140
Last Week
341,946
Last Month
1,415,646
Last Year
11,535,916
MIT License
4,589 Stars
4,686 Commits
213 Forks
18 Watchers
19 Branches
95 Contributors
Updated on Jul 01, 2025
Latest Version
1.18.0
Package Id
@zag-js/core@1.18.0
Unpacked Size
33.39 kB
Size
6.69 kB
File Count
7
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 30, 2025
Cumulative downloads
Total Downloads
Last Day
-2.5%
22,140
Compared to previous day
Last Week
-6.7%
341,946
Compared to previous week
Last Month
7.3%
1,415,646
Compared to previous month
Last Year
335.8%
11,535,916
Compared to previous year
2
1
This package contains a minimal implementation of XState FSM for finite state machines with addition of extra features we need for our components.
setTimeout
)setInterval
)and
, or
, not
)To better understand the state machines, we strongly recommend going though the xstate docs and videos. It'll give you the foundations you need.
Installation
1npm i @zag-js/core 2# or 3yarn add @zag-js/core
Usage (machine):
1import { createMachine } from "@zag-js/core" 2 3const toggleMachine = createMachine({ 4 id: "toggle", 5 initialState() { 6 return "inactive" 7 }, 8 states: { 9 inactive: { on: { TOGGLE: "active" } }, 10 active: { on: { TOGGLE: "inactive" } }, 11 }, 12}) 13 14toggleMachine.start() 15console.log(toggleMachine.state.value) // => "inactive" 16 17toggleMachine.send("TOGGLE") 18console.log(toggleMachine.state.value) // => "active" 19 20toggleMachine.send("TOGGLE") 21console.log(toggleMachine.state.value) // => "inactive"
Usage (service):
1import { createMachine } from "@zag-js/core" 2 3const toggleMachine = createMachine({...}) 4toggleMachine.start() 5 6toggleService.subscribe((state) => { 7 console.log(state.value) 8}) 9 10toggleService.send("TOGGLE") 11toggleService.send("TOGGLE") 12toggleService.stop()
createMachine(config, options)
Creates a new finite state machine from the config.
Argument | Type | Description |
---|---|---|
config | object (see below) | The config object for creating the machine. |
options | object (see below) | The optional options object. |
Returns:
A Machine
, which provides:
machine.initialState
: the machine's resolved initial statemachine.start()
: the function to start the machine in the specified initial state.machine.stop()
: the function to stop the machine completely. It also cleans up all scheduled actions and timeouts.machine.transition(state, event)
: a transition function that returns the next state given the current state
and
event
. It also performs any delayed, entry or exit side-effects.machine.send(event)
: a transition function instructs the machine to execute a transition based on the event.machine.onTransition(fn)
: a function that gets called when the machine transition function instructs the machine to
execute a transition based on the event.machine.onChange(fn)
: a function that gets called when the machine's context value changes.machine.state
: the state object that describes the machine at a specific point in time. It contains the following
properties:
value
: the current state valuepreviousValue
: the previous state valueevent
: the event that triggered the transition to the current statenextEvents
: the list of events the machine can respond to at its current statetags
: the tags associated with this statedone
: whether the machine that reached its final statecontext
: the current context valuematches(...)
: a function used to test whether the current state matches one or more state valuesThe machine config has this schema:
id
(string) - an identifier for the type of machine this is. Useful for debugging.context
(object) - the extended state data that represents quantitative data (string, number, objects, etc) that can
be modified in the machine.initial
(string) - the key of the initial state.states
(object) - an object mapping state names (keys) to stateson
(object) - an global mapping of event types to transitions. If specified, this event will called if the state
node doesn't handle the emitted event.on
(object) - an object mapping event types (keys) to transitionsString syntax:
{ target: stateName }
Object syntax:
target
(string) - the state name to transition to.actions
(Action | Action[]) - the action(s) to execute when this transition is taken.guard
(Guard) - the condition (predicate function) to test. If it returns true
, the transition will be taken.actions?
(object) - a lookup object for your string actions.guards?
(object) - a lookup object for your string guards specified as guard
in the machine.activities?
(object) - a lookup object for your string activities.delays?
(object) - a lookup object for your string delays used in after
and every
config.The action function to execute while transitioning from one state to another. It takes the following arguments:
context
(any) - the machine's current context
.event
(object) - the event that caused the action to be executed.7.5/10
Summary
@zag-js/core prototype pollution
Affected Versions
< 0.82.2
Patched Versions
0.82.2
No security vulnerabilities found.