-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathBox.tsx
40 lines (37 loc) · 1.13 KB
/
Box.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {ElementType} from '@solid-aria/types';
import clsx from 'clsx';
import type {
DynamicProps,
WithRef,
} from 'solid-headless/dist/types/utils/dynamic-prop';
import type {JSXElement, PropsWithChildren} from 'solid-js';
import {omitProps, pickProps} from 'solid-use/props';
import {sprinkles, Sprinkles} from '../../theme';
import {styled} from '../../utils';
import {boxBase} from './Box.css';
type BoxParameters = {
// Fallback to support both index number and string (ex. 2 | "2")
[key in keyof Sprinkles]: Sprinkles[key] | `${Sprinkles[key] & number}`;
};
export type BoxProps<T extends ElementType = 'div'> = Partial<BoxParameters> & {
as?: T;
} & WithRef<T> &
Omit<DynamicProps<T>, 'as' | 'disabled' | 'ref'>;
export function Box<T extends ElementType = 'div'>(
props: PropsWithChildren<BoxProps<T>>,
): JSXElement {
return (
<styled.div
{...omitProps(props, ['as', 'ref'])}
as={props.as ?? 'div'}
ref={props.ref}
class={clsx(
boxBase,
props.class,
sprinkles(pickProps(props, [...sprinkles.properties.keys()])),
)}
>
{props.children}
</styled.div>
);
}