1 | import * as React from "react";
|
2 | import { createComponent } from "reakit-system/createComponent";
|
3 | import { createHook } from "reakit-system/createHook";
|
4 | import { shallowEqual } from "reakit-utils/shallowEqual";
|
5 | import { BOX_KEYS } from "./__keys";
|
6 |
|
7 | export type BoxOptions = {
|
8 | |
9 |
|
10 |
|
11 |
|
12 | unstable_system?: any;
|
13 | };
|
14 |
|
15 | export type BoxHTMLProps = React.HTMLAttributes<any> &
|
16 | React.RefAttributes<any> & {
|
17 | |
18 |
|
19 |
|
20 |
|
21 | wrapElement?: (element: React.ReactNode) => React.ReactNode;
|
22 | };
|
23 |
|
24 | export type BoxProps = BoxOptions & BoxHTMLProps;
|
25 |
|
26 | export const useBox = createHook<BoxOptions, BoxHTMLProps>({
|
27 | name: "Box",
|
28 | keys: BOX_KEYS,
|
29 | propsAreEqual(prev, next) {
|
30 | const { unstable_system: prevSystem, ...prevProps } = prev;
|
31 | const { unstable_system: nextSystem, ...nextProps } = next;
|
32 | if (prevSystem !== nextSystem && !shallowEqual(prevSystem, nextSystem)) {
|
33 | return false;
|
34 | }
|
35 | return shallowEqual(prevProps, nextProps);
|
36 | },
|
37 | });
|
38 |
|
39 | export const Box = createComponent({
|
40 | as: "div",
|
41 | useHook: useBox,
|
42 | });
|