-
Notifications
You must be signed in to change notification settings - Fork 59
/
makeStyles.ts
29 lines (24 loc) · 1018 Bytes
/
makeStyles.ts
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
import { makeStyles as vanillaMakeStyles } from '@griffel/core';
import type { GriffelStyle } from '@griffel/core';
import { insertionFactory } from './insertionFactory';
import { useRenderer } from './RendererContext';
import { useTextDirection } from './TextDirectionContext';
import { isInsideComponent } from './utils/isInsideComponent';
export function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {
const getStyles = vanillaMakeStyles(stylesBySlots, insertionFactory);
if (process.env.NODE_ENV !== 'production') {
if (isInsideComponent()) {
throw new Error(
[
"makeStyles(): this function cannot be called in component's scope.",
'All makeStyles() calls should be top level i.e. in a root scope of a file.',
].join(' '),
);
}
}
return function useClasses(): Record<Slots, string> {
const dir = useTextDirection();
const renderer = useRenderer();
return getStyles({ dir, renderer });
};
}