UNPKG

1.09 kBPlain TextView Raw
1import { createComponent } from "reakit-system/createComponent";
2import { createHook } from "reakit-system/createHook";
3import { RoleOptions, RoleHTMLProps, useRole } from "../Role/Role";
4import { VISUALLY_HIDDEN_KEYS } from "./__keys";
5
6export type VisuallyHiddenOptions = RoleOptions;
7
8export type VisuallyHiddenHTMLProps = RoleHTMLProps;
9
10export type VisuallyHiddenProps = VisuallyHiddenOptions &
11 VisuallyHiddenHTMLProps;
12
13export const useVisuallyHidden = createHook<
14 VisuallyHiddenOptions,
15 VisuallyHiddenHTMLProps
16>({
17 name: "VisuallyHidden",
18 compose: useRole,
19 keys: VISUALLY_HIDDEN_KEYS,
20
21 useProps(_, { style: htmlStyle, ...htmlProps }) {
22 return {
23 style: {
24 border: 0,
25 clip: "rect(0 0 0 0)",
26 height: "1px",
27 margin: "-1px",
28 overflow: "hidden",
29 padding: 0,
30 position: "absolute",
31 whiteSpace: "nowrap",
32 width: "1px",
33 ...htmlStyle,
34 },
35 ...htmlProps,
36 };
37 },
38});
39
40export const VisuallyHidden = createComponent({
41 as: "span",
42 memo: true,
43 useHook: useVisuallyHidden,
44});