@primer/styled-react 0.0.0-20251007205659 → 0.0.0-20251007212126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ActionList.js +104 -0
- package/dist/components/ActionMenu.js +17 -0
- package/dist/components/Autocomplete.js +17 -0
- package/dist/components/Avatar.js +13 -0
- package/dist/components/BaseStyles.d.ts +17 -0
- package/dist/components/BaseStyles.d.ts.map +1 -0
- package/dist/components/BaseStyles.js +51 -0
- package/dist/components/Breadcrumbs.js +37 -0
- package/dist/components/Checkbox.js +13 -0
- package/dist/components/CheckboxGroup.js +38 -0
- package/dist/components/CircleBadge.js +11 -0
- package/dist/components/CounterLabel.js +13 -0
- package/dist/components/DataTable.js +32 -0
- package/dist/components/Dialog.js +42 -0
- package/dist/components/Flash.js +11 -0
- package/dist/components/Header.js +51 -0
- package/dist/components/Heading.js +11 -0
- package/dist/components/Label.js +25 -0
- package/dist/components/Link.js +25 -0
- package/dist/components/LinkButton.js +11 -0
- package/dist/components/NavList.js +56 -0
- package/dist/components/Overlay.js +11 -0
- package/dist/{Tooltip-DIHgr01r.js → components/PageHeader.js} +4 -49
- package/dist/components/PageLayout.js +39 -0
- package/dist/components/RadioGroup.js +38 -0
- package/dist/components/RelativeTime.js +13 -0
- package/dist/components/SegmentedControl.js +27 -0
- package/dist/components/Spinner.js +12 -0
- package/dist/components/StateLabel.js +13 -0
- package/dist/components/SubNav.js +23 -0
- package/dist/components/Text.js +26 -0
- package/dist/components/ThemeProvider.d.ts +30 -0
- package/dist/components/ThemeProvider.d.ts.map +1 -0
- package/dist/components/ThemeProvider.js +196 -0
- package/dist/components/Timeline.js +46 -0
- package/dist/components/ToggleSwitch.js +13 -0
- package/dist/components/Token.js +36 -0
- package/dist/components/Tooltip.js +13 -0
- package/dist/components/Truncate.js +11 -0
- package/dist/components/UnderlineNav.js +43 -0
- package/dist/components/UnderlinePanels.js +27 -0
- package/dist/components/deprecated/ActionList.js +48 -0
- package/dist/components/deprecated/DialogV1.js +44 -0
- package/dist/components/deprecated/Octicon.js +39 -0
- package/dist/components/deprecated/TabNav.js +44 -0
- package/dist/components/deprecated/Tooltip.js +31 -0
- package/dist/components.json +1 -0
- package/dist/deprecated.js +5 -179
- package/dist/experimental.js +5 -55
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -666
- package/package.json +3 -3
|
@@ -1,44 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { forwardRef } from 'react';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { PageHeader as PageHeader$1, sx, Box } from '@primer/react';
|
|
4
2
|
import styled from 'styled-components';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// @ts-expect-error - PrimerDialog is not recognized as a valid component type
|
|
8
|
-
return /*#__PURE__*/jsx(Box, {
|
|
9
|
-
as: Dialog$1,
|
|
10
|
-
ref: ref,
|
|
11
|
-
...props
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
const DialogHeader = /*#__PURE__*/forwardRef(function DialogHeader(props, ref) {
|
|
15
|
-
return /*#__PURE__*/jsx(Box, {
|
|
16
|
-
as: Dialog$1.Header,
|
|
17
|
-
ref: ref,
|
|
18
|
-
...props
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
const DialogBody = /*#__PURE__*/forwardRef(function DialogBody(props, ref) {
|
|
22
|
-
// @ts-expect-error - PrimerDialog.Body is not recognized as a valid component type
|
|
23
|
-
return /*#__PURE__*/jsx(Box, {
|
|
24
|
-
as: Dialog$1.Body,
|
|
25
|
-
ref: ref,
|
|
26
|
-
...props
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
const DialogFooter = /*#__PURE__*/forwardRef(function DialogFooter(props, ref) {
|
|
30
|
-
return /*#__PURE__*/jsx(Box, {
|
|
31
|
-
as: Dialog$1.Footer,
|
|
32
|
-
ref: ref,
|
|
33
|
-
...props
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
const Dialog = Object.assign(DialogImpl, {
|
|
37
|
-
Buttons: Dialog$1.Buttons,
|
|
38
|
-
Header: DialogHeader,
|
|
39
|
-
Body: DialogBody,
|
|
40
|
-
Footer: DialogFooter
|
|
41
|
-
});
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
42
5
|
|
|
43
6
|
const StyledPageHeader = styled(PageHeader$1).withConfig({
|
|
44
7
|
shouldForwardProp: prop => prop !== 'sx'
|
|
@@ -141,12 +104,4 @@ const PageHeader = Object.assign(PageHeaderImpl, {
|
|
|
141
104
|
TrailingAction: PageHeader$1.TrailingAction
|
|
142
105
|
});
|
|
143
106
|
|
|
144
|
-
|
|
145
|
-
return /*#__PURE__*/jsx(Box, {
|
|
146
|
-
as: Tooltip$1,
|
|
147
|
-
ref: ref,
|
|
148
|
-
...props
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
export { Dialog as D, PageHeader as P, Tooltip as T };
|
|
107
|
+
export { PageHeader };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { sx, PageLayout as PageLayout$1 } from '@primer/react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
const Wrapper = styled.div.withConfig({
|
|
7
|
+
displayName: "PageLayout__Wrapper",
|
|
8
|
+
componentId: "sc-pjybtc-0"
|
|
9
|
+
})(["", ""], sx);
|
|
10
|
+
const PageLayoutImpl = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
11
|
+
// @ts-expect-error - PrimerPageLayout is not recognized as a valid component type
|
|
12
|
+
return /*#__PURE__*/jsx(Wrapper, {
|
|
13
|
+
as: PageLayout$1,
|
|
14
|
+
ref: ref,
|
|
15
|
+
...props
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
const PageLayoutContent = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
19
|
+
return /*#__PURE__*/jsx(Wrapper, {
|
|
20
|
+
as: PageLayout$1.Content,
|
|
21
|
+
ref: ref,
|
|
22
|
+
...props
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
const PageLayoutPane = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
26
|
+
return /*#__PURE__*/jsx(Wrapper, {
|
|
27
|
+
as: PageLayout$1.Pane,
|
|
28
|
+
ref: ref,
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
const PageLayout = Object.assign(PageLayoutImpl, {
|
|
33
|
+
Content: PageLayoutContent,
|
|
34
|
+
Header: PageLayout$1.Header,
|
|
35
|
+
Pane: PageLayoutPane,
|
|
36
|
+
Footer: PageLayout$1.Footer
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { PageLayout };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Box, RadioGroup as RadioGroup$1 } from '@primer/react';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const RadioGroupImpl = props => {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: RadioGroup$1,
|
|
8
|
+
...props
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// Define local types based on the internal component props
|
|
13
|
+
|
|
14
|
+
const CheckboxOrRadioGroupLabel = props => {
|
|
15
|
+
return /*#__PURE__*/jsx(Box, {
|
|
16
|
+
as: RadioGroup$1.Label,
|
|
17
|
+
...props
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const CheckboxOrRadioGroupCaption = props => {
|
|
21
|
+
return /*#__PURE__*/jsx(Box, {
|
|
22
|
+
as: RadioGroup$1.Caption,
|
|
23
|
+
...props
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const CheckboxOrRadioGroupValidation = props => {
|
|
27
|
+
return /*#__PURE__*/jsx(Box, {
|
|
28
|
+
as: RadioGroup$1.Validation,
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const RadioGroup = Object.assign(RadioGroupImpl, {
|
|
33
|
+
Label: CheckboxOrRadioGroupLabel,
|
|
34
|
+
Caption: CheckboxOrRadioGroupCaption,
|
|
35
|
+
Validation: CheckboxOrRadioGroupValidation
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export { RadioGroup };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Box, RelativeTime as RelativeTime$1 } from '@primer/react';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
function RelativeTime(props) {
|
|
6
|
+
// @ts-expect-error the types for Box are not correctly inferred here
|
|
7
|
+
return /*#__PURE__*/jsx(Box, {
|
|
8
|
+
as: RelativeTime$1,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { RelativeTime };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Box, SegmentedControl as SegmentedControl$1 } from '@primer/react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
const SegmentedControlButton = props => {
|
|
5
|
+
return /*#__PURE__*/jsx(Box, {
|
|
6
|
+
as: SegmentedControl$1.Button,
|
|
7
|
+
...props
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const SegmentedControlIconButton = props => {
|
|
11
|
+
return /*#__PURE__*/jsx(Box, {
|
|
12
|
+
as: SegmentedControl$1.IconButton,
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const SegmentedControlImpl = props => {
|
|
17
|
+
return /*#__PURE__*/jsx(Box, {
|
|
18
|
+
as: SegmentedControl$1,
|
|
19
|
+
...props
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const SegmentedControl = Object.assign(SegmentedControlImpl, {
|
|
23
|
+
Button: SegmentedControlButton,
|
|
24
|
+
IconButton: SegmentedControlIconButton
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export { SegmentedControl };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Box, StateLabel as StateLabel$1 } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const StateLabel = /*#__PURE__*/forwardRef(function StateLabel(props, ref) {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: StateLabel$1,
|
|
8
|
+
ref: ref,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { StateLabel };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Box, SubNav as SubNav$1 } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const SubNavImpl = /*#__PURE__*/forwardRef(function SubNav(props, ref) {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: SubNav$1,
|
|
8
|
+
ref: ref,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
const SubNavLink = /*#__PURE__*/forwardRef(function SubNavLink(props, ref) {
|
|
13
|
+
return /*#__PURE__*/jsx(Box, {
|
|
14
|
+
as: SubNav$1.Link,
|
|
15
|
+
ref: ref,
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
const SubNav = Object.assign(SubNavImpl, {
|
|
20
|
+
Link: SubNavLink
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export { SubNav };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Text as Text$1, sx } from '@primer/react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
const StyledText = styled(Text$1).withConfig({
|
|
7
|
+
shouldForwardProp: prop => prop !== 'sx'
|
|
8
|
+
}).withConfig({
|
|
9
|
+
displayName: "Text__StyledText",
|
|
10
|
+
componentId: "sc-1klmep6-0"
|
|
11
|
+
})(["", ""], sx);
|
|
12
|
+
const Text = /*#__PURE__*/forwardRef(({
|
|
13
|
+
as,
|
|
14
|
+
...props
|
|
15
|
+
}, ref) => {
|
|
16
|
+
return /*#__PURE__*/jsx(StyledText, {
|
|
17
|
+
...props,
|
|
18
|
+
...(as ? {
|
|
19
|
+
forwardedAs: as
|
|
20
|
+
} : {}),
|
|
21
|
+
ref: ref
|
|
22
|
+
});
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { Text };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const defaultColorMode = "day";
|
|
3
|
+
export type Theme = {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
type ColorMode = 'day' | 'night' | 'light' | 'dark';
|
|
7
|
+
export type ColorModeWithAuto = ColorMode | 'auto';
|
|
8
|
+
export type ThemeProviderProps = {
|
|
9
|
+
theme?: Theme;
|
|
10
|
+
colorMode?: ColorModeWithAuto;
|
|
11
|
+
dayScheme?: string;
|
|
12
|
+
nightScheme?: string;
|
|
13
|
+
preventSSRMismatch?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const ThemeProvider: React.FC<React.PropsWithChildren<ThemeProviderProps>>;
|
|
16
|
+
export declare function useTheme(): {
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
colorScheme?: string;
|
|
19
|
+
colorMode?: ColorModeWithAuto;
|
|
20
|
+
resolvedColorMode?: ColorMode;
|
|
21
|
+
resolvedColorScheme?: string;
|
|
22
|
+
dayScheme?: string;
|
|
23
|
+
nightScheme?: string;
|
|
24
|
+
setColorMode: React.Dispatch<React.SetStateAction<ColorModeWithAuto>>;
|
|
25
|
+
setDayScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
26
|
+
setNightScheme: React.Dispatch<React.SetStateAction<string>>;
|
|
27
|
+
};
|
|
28
|
+
export declare function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string): string;
|
|
29
|
+
export default ThemeProvider;
|
|
30
|
+
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/components/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,eAAO,MAAM,gBAAgB,QAAQ,CAAA;AAKrC,MAAM,MAAM,KAAK,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAA;AACxC,KAAK,SAAS,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;AACnD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,MAAM,CAAA;AAElD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AA8BD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAiF/E,CAAA;AAED,wBAAgB,QAAQ;YA9Gd,KAAK;kBACC,MAAM;gBACR,iBAAiB;wBACT,SAAS;0BACP,MAAM;gBAChB,MAAM;kBACJ,MAAM;kBACN,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;kBACvD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;oBAC1C,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;EAuG7D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,UAG1F;AAqGD,eAAe,aAAa,CAAA"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { ThemeProvider as ThemeProvider$1 } from 'styled-components';
|
|
4
|
+
import { theme, useId, useSyncedState } from '@primer/react';
|
|
5
|
+
import deepmerge from 'deepmerge';
|
|
6
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
const defaultColorMode = 'day';
|
|
9
|
+
const defaultDayScheme = 'light';
|
|
10
|
+
const defaultNightScheme = 'dark';
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
|
|
14
|
+
const ThemeContext = /*#__PURE__*/React.createContext({
|
|
15
|
+
setColorMode: () => null,
|
|
16
|
+
setDayScheme: () => null,
|
|
17
|
+
setNightScheme: () => null
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// inspired from __NEXT_DATA__, we use application/json to avoid CSRF policy with inline scripts
|
|
21
|
+
const getServerHandoff = id => {
|
|
22
|
+
try {
|
|
23
|
+
const serverData = document.getElementById(`__PRIMER_DATA_${id}__`)?.textContent;
|
|
24
|
+
if (serverData) return JSON.parse(serverData);
|
|
25
|
+
} catch (_error) {
|
|
26
|
+
// if document/element does not exist or JSON is invalid, supress error
|
|
27
|
+
}
|
|
28
|
+
return {};
|
|
29
|
+
};
|
|
30
|
+
const ThemeProvider = ({
|
|
31
|
+
children,
|
|
32
|
+
...props
|
|
33
|
+
}) => {
|
|
34
|
+
// Get fallback values from parent ThemeProvider (if exists)
|
|
35
|
+
const {
|
|
36
|
+
theme: fallbackTheme,
|
|
37
|
+
colorMode: fallbackColorMode,
|
|
38
|
+
dayScheme: fallbackDayScheme,
|
|
39
|
+
nightScheme: fallbackNightScheme
|
|
40
|
+
} = useTheme();
|
|
41
|
+
|
|
42
|
+
// Initialize state
|
|
43
|
+
const theme$1 = props.theme ?? fallbackTheme ?? theme;
|
|
44
|
+
const uniqueDataId = useId();
|
|
45
|
+
const {
|
|
46
|
+
resolvedServerColorMode
|
|
47
|
+
} = getServerHandoff(uniqueDataId);
|
|
48
|
+
const resolvedColorModePassthrough = React.useRef(resolvedServerColorMode);
|
|
49
|
+
const [colorMode, setColorMode] = useSyncedState(props.colorMode ?? fallbackColorMode ?? defaultColorMode);
|
|
50
|
+
const [dayScheme, setDayScheme] = useSyncedState(props.dayScheme ?? fallbackDayScheme ?? defaultDayScheme);
|
|
51
|
+
const [nightScheme, setNightScheme] = useSyncedState(props.nightScheme ?? fallbackNightScheme ?? defaultNightScheme);
|
|
52
|
+
const systemColorMode = useSystemColorMode();
|
|
53
|
+
const resolvedColorMode = resolvedColorModePassthrough.current || resolveColorMode(colorMode, systemColorMode);
|
|
54
|
+
const colorScheme = chooseColorScheme(resolvedColorMode, dayScheme, nightScheme);
|
|
55
|
+
const {
|
|
56
|
+
resolvedTheme,
|
|
57
|
+
resolvedColorScheme
|
|
58
|
+
} = React.useMemo(() => applyColorScheme(theme$1, colorScheme), [theme$1, colorScheme]);
|
|
59
|
+
|
|
60
|
+
// this effect will only run on client
|
|
61
|
+
React.useEffect(function updateColorModeAfterServerPassthrough() {
|
|
62
|
+
const resolvedColorModeOnClient = resolveColorMode(colorMode, systemColorMode);
|
|
63
|
+
if (resolvedColorModePassthrough.current) {
|
|
64
|
+
// if the resolved color mode passed on from the server is not the resolved color mode on client, change it!
|
|
65
|
+
if (resolvedColorModePassthrough.current !== resolvedColorModeOnClient) {
|
|
66
|
+
window.setTimeout(() => {
|
|
67
|
+
// use ReactDOM.flushSync to prevent automatic batching of state updates since React 18
|
|
68
|
+
// ref: https://github.com/reactwg/react-18/discussions/21
|
|
69
|
+
ReactDOM.flushSync(() => {
|
|
70
|
+
// override colorMode to whatever is resolved on the client to get a re-render
|
|
71
|
+
setColorMode(resolvedColorModeOnClient);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// immediately after that, set the colorMode to what the user passed to respond to system color mode changes
|
|
75
|
+
setColorMode(colorMode);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
resolvedColorModePassthrough.current = null;
|
|
79
|
+
}
|
|
80
|
+
}, [colorMode, systemColorMode, setColorMode]);
|
|
81
|
+
return /*#__PURE__*/jsx(ThemeContext.Provider, {
|
|
82
|
+
value: {
|
|
83
|
+
theme: resolvedTheme,
|
|
84
|
+
colorScheme,
|
|
85
|
+
colorMode,
|
|
86
|
+
resolvedColorMode,
|
|
87
|
+
resolvedColorScheme,
|
|
88
|
+
dayScheme,
|
|
89
|
+
nightScheme,
|
|
90
|
+
setColorMode,
|
|
91
|
+
setDayScheme,
|
|
92
|
+
setNightScheme
|
|
93
|
+
},
|
|
94
|
+
children: /*#__PURE__*/jsxs(ThemeProvider$1, {
|
|
95
|
+
theme: resolvedTheme,
|
|
96
|
+
children: [children, props.preventSSRMismatch ? /*#__PURE__*/jsx("script", {
|
|
97
|
+
type: "application/json",
|
|
98
|
+
id: `__PRIMER_DATA_${uniqueDataId}__`,
|
|
99
|
+
dangerouslySetInnerHTML: {
|
|
100
|
+
__html: JSON.stringify({
|
|
101
|
+
resolvedServerColorMode: resolvedColorMode
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
}) : null]
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
function useTheme() {
|
|
109
|
+
return React.useContext(ThemeContext);
|
|
110
|
+
}
|
|
111
|
+
function useSystemColorMode() {
|
|
112
|
+
const [systemColorMode, setSystemColorMode] = React.useState(getSystemColorMode);
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
115
|
+
const media = window?.matchMedia?.('(prefers-color-scheme: dark)');
|
|
116
|
+
function matchesMediaToColorMode(matches) {
|
|
117
|
+
return matches ? 'night' : 'day';
|
|
118
|
+
}
|
|
119
|
+
function handleChange(event) {
|
|
120
|
+
const isNight = event.matches;
|
|
121
|
+
setSystemColorMode(matchesMediaToColorMode(isNight));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
125
|
+
if (media) {
|
|
126
|
+
// just in case the preference changed before the event listener was attached
|
|
127
|
+
const isNight = media.matches;
|
|
128
|
+
setSystemColorMode(matchesMediaToColorMode(isNight));
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
130
|
+
if (media.addEventListener !== undefined) {
|
|
131
|
+
media.addEventListener('change', handleChange);
|
|
132
|
+
return function cleanup() {
|
|
133
|
+
media.removeEventListener('change', handleChange);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
137
|
+
else if (media.addListener !== undefined) {
|
|
138
|
+
media.addListener(handleChange);
|
|
139
|
+
return function cleanup() {
|
|
140
|
+
media.removeListener(handleChange);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, []);
|
|
145
|
+
return systemColorMode;
|
|
146
|
+
}
|
|
147
|
+
function getSystemColorMode() {
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
149
|
+
if (typeof window !== 'undefined' && window.matchMedia?.('(prefers-color-scheme: dark)')?.matches) {
|
|
150
|
+
return 'night';
|
|
151
|
+
}
|
|
152
|
+
return 'day';
|
|
153
|
+
}
|
|
154
|
+
function resolveColorMode(colorMode, systemColorMode) {
|
|
155
|
+
switch (colorMode) {
|
|
156
|
+
case 'auto':
|
|
157
|
+
return systemColorMode;
|
|
158
|
+
default:
|
|
159
|
+
return colorMode;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function chooseColorScheme(colorMode, dayScheme, nightScheme) {
|
|
163
|
+
switch (colorMode) {
|
|
164
|
+
case 'day':
|
|
165
|
+
case 'light':
|
|
166
|
+
return dayScheme;
|
|
167
|
+
case 'dark':
|
|
168
|
+
case 'night':
|
|
169
|
+
return nightScheme;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function applyColorScheme(theme, colorScheme) {
|
|
173
|
+
if (!theme.colorSchemes) {
|
|
174
|
+
return {
|
|
175
|
+
resolvedTheme: theme,
|
|
176
|
+
resolvedColorScheme: undefined
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (!theme.colorSchemes[colorScheme]) {
|
|
180
|
+
// eslint-disable-next-line no-console
|
|
181
|
+
console.error(`\`${colorScheme}\` scheme not defined in \`theme.colorSchemes\``);
|
|
182
|
+
|
|
183
|
+
// Apply the first defined color scheme
|
|
184
|
+
const defaultColorScheme = Object.keys(theme.colorSchemes)[0];
|
|
185
|
+
return {
|
|
186
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[defaultColorScheme]),
|
|
187
|
+
resolvedColorScheme: defaultColorScheme
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
resolvedTheme: deepmerge(theme, theme.colorSchemes[colorScheme]),
|
|
192
|
+
resolvedColorScheme: colorScheme
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { ThemeProvider, ThemeProvider as default, defaultColorMode, useTheme };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Box, Timeline as Timeline$1 } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const TimelineImpl = /*#__PURE__*/forwardRef(function Timeline(props, ref) {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: Timeline$1,
|
|
8
|
+
ref: ref,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
const TimelineItem = /*#__PURE__*/forwardRef(function TimelineItem(props, ref) {
|
|
13
|
+
return /*#__PURE__*/jsx(Box, {
|
|
14
|
+
as: Timeline$1.Item,
|
|
15
|
+
ref: ref,
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
function TimelineBadge(props) {
|
|
20
|
+
return /*#__PURE__*/jsx(Box, {
|
|
21
|
+
as: Timeline$1.Badge,
|
|
22
|
+
...props
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const TimelineBody = /*#__PURE__*/forwardRef(function TimelineBody(props, ref) {
|
|
26
|
+
return /*#__PURE__*/jsx(Box, {
|
|
27
|
+
as: Timeline$1.Body,
|
|
28
|
+
ref: ref,
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
const TimelineBreak = /*#__PURE__*/forwardRef(function TimelineBreak(props, ref) {
|
|
33
|
+
return /*#__PURE__*/jsx(Box, {
|
|
34
|
+
as: Timeline$1.Break,
|
|
35
|
+
ref: ref,
|
|
36
|
+
...props
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
const Timeline = Object.assign(TimelineImpl, {
|
|
40
|
+
Item: TimelineItem,
|
|
41
|
+
Badge: TimelineBadge,
|
|
42
|
+
Body: TimelineBody,
|
|
43
|
+
Break: TimelineBreak
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export { Timeline };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Box, ToggleSwitch as ToggleSwitch$1 } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const ToggleSwitch = /*#__PURE__*/forwardRef(function ToggleSwitch(props, ref) {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: ToggleSwitch$1,
|
|
8
|
+
ref: ref,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { ToggleSwitch };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTheme, theme, Token as Token$1 } from '@primer/react';
|
|
3
|
+
import css from '@styled-system/css';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
const Token = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
sx: sxProp,
|
|
8
|
+
style,
|
|
9
|
+
...rest
|
|
10
|
+
}, ref) => {
|
|
11
|
+
const contextTheme = useTheme();
|
|
12
|
+
const theme$1 = contextTheme.theme || theme;
|
|
13
|
+
|
|
14
|
+
// If no sx prop is provided, just return PrimerToken directly
|
|
15
|
+
if (!sxProp) {
|
|
16
|
+
return /*#__PURE__*/jsx(Token$1, {
|
|
17
|
+
...rest,
|
|
18
|
+
style: style,
|
|
19
|
+
ref: ref
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Convert sx to CSS styles using the theme context
|
|
24
|
+
const sxStyles = css(sxProp)(theme$1);
|
|
25
|
+
const mergedStyle = {
|
|
26
|
+
...sxStyles,
|
|
27
|
+
...style
|
|
28
|
+
};
|
|
29
|
+
return /*#__PURE__*/jsx(Token$1, {
|
|
30
|
+
...rest,
|
|
31
|
+
style: mergedStyle,
|
|
32
|
+
ref: ref
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { Token };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Box, Tooltip as Tooltip$1 } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
const Tooltip = /*#__PURE__*/forwardRef(function Tooltip(props, ref) {
|
|
6
|
+
return /*#__PURE__*/jsx(Box, {
|
|
7
|
+
as: Tooltip$1,
|
|
8
|
+
ref: ref,
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { Tooltip };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Truncate as Truncate$1, sx } from '@primer/react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
const Truncate = styled(Truncate$1).withConfig({
|
|
5
|
+
shouldForwardProp: prop => prop !== 'sx'
|
|
6
|
+
}).withConfig({
|
|
7
|
+
displayName: "Truncate",
|
|
8
|
+
componentId: "sc-x3i4it-0"
|
|
9
|
+
})(["", ""], sx);
|
|
10
|
+
|
|
11
|
+
export { Truncate };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { UnderlineNav as UnderlineNav$1, sx, Box } from '@primer/react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
const StyledUnderlineNav = /*#__PURE__*/forwardRef(function UnderlineNav(props, ref) {
|
|
7
|
+
return /*#__PURE__*/jsx(Box, {
|
|
8
|
+
as: UnderlineNav$1,
|
|
9
|
+
ref: ref,
|
|
10
|
+
...props
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
const UnderlineNavImpl = /*#__PURE__*/forwardRef(({
|
|
14
|
+
as,
|
|
15
|
+
...props
|
|
16
|
+
}, ref) => /*#__PURE__*/jsx(StyledUnderlineNav, {
|
|
17
|
+
...props,
|
|
18
|
+
...(as ? {
|
|
19
|
+
forwardedAs: as
|
|
20
|
+
} : {}),
|
|
21
|
+
ref: ref
|
|
22
|
+
}));
|
|
23
|
+
const StyledUnderlineNavItem = styled(UnderlineNav$1.Item).withConfig({
|
|
24
|
+
shouldForwardProp: prop => prop !== 'sx'
|
|
25
|
+
}).withConfig({
|
|
26
|
+
displayName: "UnderlineNav__StyledUnderlineNavItem",
|
|
27
|
+
componentId: "sc-dx6br2-0"
|
|
28
|
+
})(["", ""], sx);
|
|
29
|
+
const UnderlineNavItem = /*#__PURE__*/forwardRef(({
|
|
30
|
+
as,
|
|
31
|
+
...props
|
|
32
|
+
}, ref) => /*#__PURE__*/jsx(StyledUnderlineNavItem, {
|
|
33
|
+
...props,
|
|
34
|
+
...(as ? {
|
|
35
|
+
forwardedAs: as
|
|
36
|
+
} : {}),
|
|
37
|
+
ref: ref
|
|
38
|
+
}));
|
|
39
|
+
const UnderlineNav = Object.assign(UnderlineNavImpl, {
|
|
40
|
+
Item: UnderlineNavItem
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { UnderlineNav, UnderlineNavImpl, UnderlineNavItem };
|