GithubHelp home page GithubHelp logo

devdoshi / zag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chakra-ui/zag

0.0 0.0 0.0 7.39 MB

Finite state machines for building accessible design systems and UI components.

Home Page: http://zagjs.com

License: MIT License

Shell 0.01% JavaScript 6.74% TypeScript 90.12% CSS 2.48% Handlebars 0.65%

zag's Introduction

Zag

Finite state machines for accessible JavaScript components

  • Write once, use everywhere ๐Ÿฆ„: The component interactions are modelled in a framework agnostic way. We provide adapters for JS frameworks like React, Solid, or Vue.
  • Focus on accessibility โ™ฟ๏ธ: Zag is built with accessibility in mind. We handle many details related to keyboard interactions, focus management, aria roles and attributes.
  • Headless โœจ: The machine APIs are completely unstyled and gives you the control to use any styling solution you prefer.
  • Powered by state machines ๐ŸŒณ: Zag is built on top of the latest ideas in Statecharts. We don't follow the SCXML specifications, but we've created an API that we think will help us build more complex components fast.

The problem

With the rise of design systems and component-driven development, there's an endless re-implementation of common component patterns (Tabs, Menu, Modal, etc.) in multiple frameworks.

Most of these implementations seem to be fairly similar in spirit, the differences being around the reactivity and effects systems for the framework (e.g. useState, useEffect in React.js). Framework specific solutions tend to grow in complexity over time and often become hard to understand, debug, improve or test.

Solution

Zag is a JavaScript API that implements common component patterns using the state machine methodology.

Installation

npm i --save @zag-js/{component}

# or

yarn add @zag-js/{component}

{component} represents any component machine like dialog (@zag-js/dialog), tooltip (@zag-js/tooltip) , etc.

For framework specific solutions, we provide simple wrappers to help you consume the component state machines.

  • โš›๏ธ @zag-js/react - React hooks for consuming machines in React applications
  • ๐Ÿ’š @zag-js/vue - Vue composition for consuming machines in Vue applications
  • ๐ŸŽท @zag-js/solid - Solid.js utilities for consuming machines in Solid.js applications

Usage

import * as toggle from "@zag-js/toggle"
import { normalizeProps, useMachine } from "@zag-js/react"

function Example() {
  // if you need access to `state` or `send` from machine
  const [state, send] = useMachine(toggle.machine({ id: "2" }))

  // convert machine details into `DOM` props
  const api = toggle.connect(state, send, normalizeProps)

  // consume into components
  return <button {...api.buttonProps}>Toggle me</button>
}

Guiding Principles

  • All component machines and tests are modelled according to the WAI-ARIA authoring practices
  • Write end-to-end tests for every component based on the WAI-ARIA spec. Regardless of the framework, users expect component patterns to work the same way!
  • All machines should be light-weight, simple, and easy to understand. Avoid using complex machine concepts like spawn, nested states, etc.

Fun Facts

Zag means to take a sharp change in direction. This clearly describes our approach of using state machines to power the logic behind UI components.

Teasers

  • When you see someone using classic react, vue or solid to build an interactive UI component that exists in Zag, tell them to "zag it!" โšก๏ธ

  • Anyone using Zag will be called a "zagger" ๐Ÿ’ฅ

  • The feeling you get when you use Zag will be called "zagadat!" ๐Ÿš€

  • The Zag community will be called "zag nation" ๐Ÿ”ฅ

Commands

Build commands

Our build is managed with esbuild and turborepo to provide fast, concurrent builds across the packages.

  • build-fast : Build the CJS and ESM versions, without the types.
  • build : Build the CJS, ESM and DTS files. This is the actual production build that we run in the CI.
  • start : The command to run when developing for Zag. It runs the build:fast command, watches for changes and rebuilds as needed.

Examples

Since zag is framework agnostic, we need a way to test it within a framework. The examples/ directory includes starter projects for the frameworks we support.

  • start-react : Starts the Next.js TypeScript project
  • start-vue : Starts the Vue 3 TypeScript project
  • start-solid : Starts the Solid TypeScript project

E2E Tests

We've setup end-to-end tests for every machine we built. We use Playwright for testing and we ensure that the component works the same way regardless of the framework.

  • e2e-react : Starts the E2E tests for the React project
  • e2e-vue : Starts the E2E tests for the Vue project
  • e2e-solid : Starts the E2E tests for the Solid project

Contributing new machines/features

  • generate-machine : Generates a new machine package in the packages/ directory. It sets up the required files and structure for new machine.
  • generate-util : Generates a new utility package in the packages/utilities directory.

Other commands

  • test : Run the tests for all packages
  • lint : Lint all packages

Inspirations

Contributions

Looking to contribute? Look for the Good First Issue label.

๐Ÿ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

๐Ÿ’ก Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a ๐Ÿ‘. This helps maintainers prioritize what to work on.

License

MIT ยฉ Segun Adebayo

zag's People

Contributors

segunadebayo avatar anubra266 avatar renovate[bot] avatar github-actions[bot] avatar codebender828 avatar martian2lee avatar renovate-bot avatar cschroeter avatar alexluong avatar malangcat avatar anilanar avatar takethefake avatar y3v4psypl avatar visualjerk avatar royal-lobster avatar timkolberger avatar moosefaceee avatar xylophonehero avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.