CVA alternative focused on style composition.
It should let us create small utilities like border that other styles can reuse.
Note
>
Update: Ariakit Styles is in alpha. If you want to try it, join us on Discord (see the #news channel).
| import { | |
| queryByLabelText, | |
| queryByRole, | |
| queryByText, | |
| } from "@testing-library/dom"; | |
| import type { ByRoleOptions, Matcher } from "@testing-library/dom"; | |
| const roles = [ | |
| "alert", | |
| "alertdialog", |
| import { useEffect, useRef, useState } from "react"; | |
| export function usePerceptibleValue<T>( | |
| value: T, | |
| { delay = 0, minDuration = 350 } = {} | |
| ) { | |
| const [perceptibleValue, setPerceptibleValue] = useState(value); | |
| const nextThresholdRef = useRef(0); | |
| useEffect(() => { |
| import { ForwardedRef, useCallback } from 'react'; | |
| type OptionalRef<T> = ForwardedRef<T> | undefined; | |
| type Cleanup = (() => void) | undefined | void; | |
| function setRef<T>(ref: OptionalRef<T>, value: T): Cleanup { | |
| if (typeof ref === 'function') { | |
| const cleanup = ref(value); |
| type AnyFunction = (...args: any[]) => any | |
| function useEvent<T extends AnyFunction>(callback?: T) { | |
| const ref = useRef<AnyFunction | undefined>(() => { | |
| throw new Error("Cannot call an event handler while rendering.") | |
| }) | |
| // Or useInsertionEffect if it's React 18 | |
| useLayoutEffect(() => { | |
| ref.current = callback | |
| }) |
Ariakit is the successor of Reakit, an open source library that provides lower-level React components and hooks for building accessible web apps, design systems, and other component libraries.
Reakit stands for React Toolkit. Ariakit stands for Aria Toolkit, which is better aligned with our goals.
Over the past years, we've been focusing more and more on the ARIA aspects of the library. In the future, we'd like to provide more framework-agnostic utilities.
| type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement>; | |
| const Link = createBlock<LinkProps>((props) => { | |
| const { onSelectionChange, selectBlockContents } = useEditorState(props); | |
| const popover = usePopoverState({ portal: true }); | |
| const [href, setHref] = useState(props.href); | |
| useEffect(() => { | |
| setHref(props.href); | |
| }, [props.href]); |
| import { | |
| Calendar, | |
| CalendarRow, | |
| CalendarCell, | |
| CalendarWeeks, | |
| CalendarWeekDays, | |
| } from "@ariakit/react"; | |
| function MyCalendar() { | |
| return ( |