-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.ts
More file actions
68 lines (61 loc) · 2.95 KB
/
Copy pathcontext.ts
File metadata and controls
68 lines (61 loc) · 2.95 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as React from 'react';
// Specialised contexts beat a god-object context here: each compound parent
// publishes exactly the info its children need, and children that don't care
// don't subscribe. All contexts default to `undefined` so a component renders
// fine without a wrapping parent.
// --- ButtonGroup --------------------------------------------------------
export interface ButtonGroupContextValue {
readonly orientation: 'horizontal' | 'vertical';
readonly size: 'sm' | 'md' | 'lg';
readonly variant: 'solid' | 'outline' | 'ghost' | 'link';
readonly attached: boolean;
/** Position helpers for the LIL to round outer corners / merge borders. */
readonly position: {
readonly index: number;
readonly isFirst: boolean;
readonly isLast: boolean;
};
}
export const ButtonGroupContext = React.createContext<ButtonGroupContextValue | undefined>(
undefined,
);
// --- List ---------------------------------------------------------------
export interface ListContextValue {
readonly density: 'compact' | 'comfortable' | 'spacious';
readonly dividers: boolean;
readonly interactive: boolean;
}
export const ListContext = React.createContext<ListContextValue | undefined>(undefined);
// --- Stack --------------------------------------------------------------
export interface StackContextValue {
readonly orientation: 'row' | 'column';
readonly align: 'start' | 'center' | 'end' | 'stretch';
readonly justify: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly';
}
export const StackContext = React.createContext<StackContextValue | undefined>(undefined);
// --- Form ---------------------------------------------------------------
export interface FormFieldContextValue {
readonly id: string;
readonly labelId: string;
readonly descriptionId: string;
readonly errorId: string;
readonly invalid: boolean;
readonly disabled: boolean;
readonly required: boolean;
}
export const FormFieldContext = React.createContext<FormFieldContextValue | undefined>(undefined);
// --- Card ---------------------------------------------------------------
export interface CardContextValue {
readonly variant: 'elevated' | 'outlined' | 'filled';
readonly density: 'compact' | 'comfortable' | 'spacious';
readonly interactive: boolean;
}
export const CardContext = React.createContext<CardContextValue | undefined>(undefined);
// Hooks ------------------------------------------------------------------
export const useButtonGroupContext = (): ButtonGroupContextValue | undefined =>
React.useContext(ButtonGroupContext);
export const useListContext = (): ListContextValue | undefined => React.useContext(ListContext);
export const useStackContext = (): StackContextValue | undefined => React.useContext(StackContext);
export const useFormFieldContext = (): FormFieldContextValue | undefined =>
React.useContext(FormFieldContext);
export const useCardContext = (): CardContextValue | undefined => React.useContext(CardContext);