@shipfox/react-ui 0.3.0 → 0.5.0
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/.storybook/main.ts +20 -10
- package/.storybook/preview.tsx +1 -1
- package/.storybook/vitest.setup.ts +4 -0
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-check.log +2 -2
- package/.turbo/turbo-type.log +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +40 -1
- package/argos.config.ts +33 -0
- package/dist/components/alert/alert.d.ts +2 -2
- package/dist/components/alert/alert.js +3 -3
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert/alert.stories.js +2 -2
- package/dist/components/alert/alert.stories.js.map +1 -1
- package/dist/components/avatar/avatar-group.js +3 -3
- package/dist/components/avatar/avatar-group.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +4 -1
- package/dist/components/avatar/avatar.d.ts.map +1 -1
- package/dist/components/avatar/avatar.js +7 -8
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/avatar/avatar.stories.js +15 -3
- package/dist/components/avatar/avatar.stories.js.map +1 -1
- package/dist/components/badge/badge.d.ts +48 -0
- package/dist/components/badge/badge.d.ts.map +1 -0
- package/dist/components/badge/badge.js +72 -0
- package/dist/components/badge/badge.js.map +1 -0
- package/dist/components/badge/badge.stories.js +802 -0
- package/dist/components/badge/badge.stories.js.map +1 -0
- package/dist/components/badge/icon-badge.d.ts +9 -0
- package/dist/components/badge/icon-badge.d.ts.map +1 -0
- package/dist/components/badge/icon-badge.js +32 -0
- package/dist/components/badge/icon-badge.js.map +1 -0
- package/dist/components/badge/index.d.ts +5 -0
- package/dist/components/badge/index.d.ts.map +1 -0
- package/dist/components/badge/index.js +6 -0
- package/dist/components/badge/index.js.map +1 -0
- package/dist/components/badge/status-badge.d.ts +9 -0
- package/dist/components/badge/status-badge.d.ts.map +1 -0
- package/dist/components/badge/status-badge.js +29 -0
- package/dist/components/badge/status-badge.js.map +1 -0
- package/dist/components/badge/user-badge.d.ts +8 -0
- package/dist/components/badge/user-badge.d.ts.map +1 -0
- package/dist/components/badge/user-badge.js +24 -0
- package/dist/components/badge/user-badge.js.map +1 -0
- package/dist/components/button/button-link.d.ts +14 -0
- package/dist/components/button/button-link.d.ts.map +1 -0
- package/dist/components/button/button-link.js +63 -0
- package/dist/components/button/button-link.js.map +1 -0
- package/dist/components/button/button-link.stories.js +127 -0
- package/dist/components/button/button-link.stories.js.map +1 -0
- package/dist/components/{button.d.ts → button/button.d.ts} +2 -2
- package/dist/components/button/button.d.ts.map +1 -0
- package/dist/components/{button.js → button/button.js} +9 -8
- package/dist/components/button/button.js.map +1 -0
- package/dist/components/{button.stories.js → button/button.stories.js} +2 -14
- package/dist/components/button/button.stories.js.map +1 -0
- package/dist/components/button/icon-button.d.ts +14 -0
- package/dist/components/button/icon-button.d.ts.map +1 -0
- package/dist/components/button/icon-button.js +53 -0
- package/dist/components/button/icon-button.js.map +1 -0
- package/dist/components/button/icon-button.stories.js +254 -0
- package/dist/components/button/icon-button.stories.js.map +1 -0
- package/dist/components/button/index.d.ts +4 -0
- package/dist/components/button/index.d.ts.map +1 -0
- package/dist/components/button/index.js +5 -0
- package/dist/components/button/index.js.map +1 -0
- package/dist/components/checkbox/checkbox-label.d.ts +14 -0
- package/dist/components/checkbox/checkbox-label.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox-label.js +82 -0
- package/dist/components/checkbox/checkbox-label.js.map +1 -0
- package/dist/components/checkbox/checkbox-links.d.ts +18 -0
- package/dist/components/checkbox/checkbox-links.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox-links.js +58 -0
- package/dist/components/checkbox/checkbox-links.js.map +1 -0
- package/dist/components/checkbox/checkbox.d.ts +9 -0
- package/dist/components/checkbox/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox.js +49 -0
- package/dist/components/checkbox/checkbox.js.map +1 -0
- package/dist/components/checkbox/checkbox.stories.js +566 -0
- package/dist/components/checkbox/checkbox.stories.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +4 -0
- package/dist/components/checkbox/index.d.ts.map +1 -0
- package/dist/components/checkbox/index.js +5 -0
- package/dist/components/checkbox/index.js.map +1 -0
- package/dist/components/code-block/code-block-footer.d.ts +26 -0
- package/dist/components/code-block/code-block-footer.d.ts.map +1 -0
- package/dist/components/code-block/code-block-footer.js +86 -0
- package/dist/components/code-block/code-block-footer.js.map +1 -0
- package/dist/components/code-block/code-block.d.ts +50 -0
- package/dist/components/code-block/code-block.d.ts.map +1 -0
- package/dist/components/code-block/code-block.js +142 -0
- package/dist/components/code-block/code-block.js.map +1 -0
- package/dist/components/code-block/code-block.stories.js +341 -0
- package/dist/components/code-block/code-block.stories.js.map +1 -0
- package/dist/components/code-block/code-content.d.ts +11 -0
- package/dist/components/code-block/code-content.d.ts.map +1 -0
- package/dist/components/code-block/code-content.js +29 -0
- package/dist/components/code-block/code-content.js.map +1 -0
- package/dist/components/code-block/code-copy-button.d.ts +11 -0
- package/dist/components/code-block/code-copy-button.d.ts.map +1 -0
- package/dist/components/code-block/code-copy-button.js +49 -0
- package/dist/components/code-block/code-copy-button.js.map +1 -0
- package/dist/components/code-block/code-tabs.d.ts +16 -0
- package/dist/components/code-block/code-tabs.d.ts.map +1 -0
- package/dist/components/code-block/code-tabs.js +98 -0
- package/dist/components/code-block/code-tabs.js.map +1 -0
- package/dist/components/code-block/index.d.ts +4 -0
- package/dist/components/code-block/index.d.ts.map +1 -0
- package/dist/components/code-block/index.js +5 -0
- package/dist/components/code-block/index.js.map +1 -0
- package/dist/components/dynamic-item/dynamic-item.d.ts +13 -0
- package/dist/components/dynamic-item/dynamic-item.d.ts.map +1 -0
- package/dist/components/dynamic-item/dynamic-item.js +43 -0
- package/dist/components/dynamic-item/dynamic-item.js.map +1 -0
- package/dist/components/dynamic-item/dynamic-item.stories.js +375 -0
- package/dist/components/dynamic-item/dynamic-item.stories.js.map +1 -0
- package/dist/components/dynamic-item/index.d.ts +2 -0
- package/dist/components/dynamic-item/index.d.ts.map +1 -0
- package/dist/components/dynamic-item/index.js +3 -0
- package/dist/components/dynamic-item/index.js.map +1 -0
- package/dist/components/icon/custom/index.d.ts +2 -0
- package/dist/components/icon/custom/index.d.ts.map +1 -1
- package/dist/components/icon/custom/index.js +2 -0
- package/dist/components/icon/custom/index.js.map +1 -1
- package/dist/components/icon/custom/slack-logo.d.ts +6 -0
- package/dist/components/icon/custom/slack-logo.d.ts.map +1 -0
- package/dist/components/icon/custom/slack-logo.js +34 -0
- package/dist/components/icon/custom/slack-logo.js.map +1 -0
- package/dist/components/icon/custom/stripe-logo.d.ts +8 -0
- package/dist/components/icon/custom/stripe-logo.d.ts.map +1 -0
- package/dist/components/icon/custom/stripe-logo.js +24 -0
- package/dist/components/icon/custom/stripe-logo.js.map +1 -0
- package/dist/components/icon/icon.d.ts +13 -2
- package/dist/components/icon/icon.d.ts.map +1 -1
- package/dist/components/icon/icon.js +14 -3
- package/dist/components/icon/icon.js.map +1 -1
- package/dist/components/icon/icon.stories.js +6 -3
- package/dist/components/icon/icon.stories.js.map +1 -1
- package/dist/components/index.d.ts +9 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +10 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/inline-tips/inline-tips.d.ts +1 -1
- package/dist/components/inline-tips/inline-tips.d.ts.map +1 -1
- package/dist/components/inline-tips/inline-tips.js +1 -1
- package/dist/components/inline-tips/inline-tips.js.map +1 -1
- package/dist/components/inline-tips/inline-tips.stories.js +5 -5
- package/dist/components/inline-tips/inline-tips.stories.js.map +1 -1
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.d.ts.map +1 -0
- package/dist/components/input/index.js +3 -0
- package/dist/components/input/index.js.map +1 -0
- package/dist/components/input/input.d.ts.map +1 -0
- package/dist/components/{input.js → input/input.js} +2 -2
- package/dist/components/input/input.js.map +1 -0
- package/dist/components/{input.stories.js → input/input.stories.js} +1 -1
- package/dist/components/input/input.stories.js.map +1 -0
- package/dist/components/item/index.d.ts +2 -0
- package/dist/components/item/index.d.ts.map +1 -0
- package/dist/components/item/index.js +3 -0
- package/dist/components/item/index.js.map +1 -0
- package/dist/components/item/item.d.ts +32 -0
- package/dist/components/item/item.d.ts.map +1 -0
- package/dist/components/item/item.js +120 -0
- package/dist/components/item/item.js.map +1 -0
- package/dist/components/item/item.stories.js +232 -0
- package/dist/components/item/item.stories.js.map +1 -0
- package/dist/components/label/index.d.ts +2 -0
- package/dist/components/label/index.d.ts.map +1 -0
- package/dist/components/label/index.js +3 -0
- package/dist/components/label/index.js.map +1 -0
- package/dist/components/label/label.d.ts +7 -0
- package/dist/components/label/label.d.ts.map +1 -0
- package/dist/components/label/label.js +13 -0
- package/dist/components/label/label.js.map +1 -0
- package/dist/components/label/label.stories.js +105 -0
- package/dist/components/label/label.stories.js.map +1 -0
- package/dist/components/moving-border/moving-border.d.ts +9 -0
- package/dist/components/moving-border/moving-border.d.ts.map +1 -0
- package/dist/components/moving-border/moving-border.js +54 -0
- package/dist/components/moving-border/moving-border.js.map +1 -0
- package/dist/components/textarea/textarea.js +1 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/theme/index.d.ts +2 -0
- package/dist/components/theme/index.d.ts.map +1 -0
- package/dist/components/theme/index.js +3 -0
- package/dist/components/theme/index.js.map +1 -0
- package/dist/components/{theme-provider.d.ts → theme/theme-provider.d.ts} +1 -1
- package/dist/components/theme/theme-provider.d.ts.map +1 -0
- package/dist/components/{theme-provider.js → theme/theme-provider.js} +1 -1
- package/dist/components/theme/theme-provider.js.map +1 -0
- package/dist/components/toast/index.d.ts +3 -0
- package/dist/components/toast/index.d.ts.map +1 -0
- package/dist/components/toast/index.js +4 -0
- package/dist/components/toast/index.js.map +1 -0
- package/dist/components/toast/toast-custom.d.ts +19 -0
- package/dist/components/toast/toast-custom.d.ts.map +1 -0
- package/dist/components/toast/toast-custom.js +134 -0
- package/dist/components/toast/toast-custom.js.map +1 -0
- package/dist/components/toast/toast.d.ts +5 -0
- package/dist/components/toast/toast.d.ts.map +1 -0
- package/dist/components/toast/toast.js +40 -0
- package/dist/components/toast/toast.js.map +1 -0
- package/dist/components/toast/toast.stories.js +326 -0
- package/dist/components/toast/toast.stories.js.map +1 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/index.d.ts.map +1 -0
- package/dist/components/tooltip/index.js +3 -0
- package/dist/components/tooltip/index.js.map +1 -0
- package/dist/components/tooltip/tooltip.d.ts +18 -5
- package/dist/components/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/tooltip/tooltip.js +63 -3
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/components/tooltip/tooltip.stories.js +560 -0
- package/dist/components/tooltip/tooltip.stories.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useResolvedTheme.d.ts +2 -0
- package/dist/hooks/useResolvedTheme.d.ts.map +1 -0
- package/dist/hooks/useResolvedTheme.js +24 -0
- package/dist/hooks/useResolvedTheme.js.map +1 -0
- package/dist/hooks/useShikiHighlight.d.ts +28 -0
- package/dist/hooks/useShikiHighlight.d.ts.map +1 -0
- package/dist/hooks/useShikiHighlight.js +106 -0
- package/dist/hooks/useShikiHighlight.js.map +1 -0
- package/dist/hooks/useShikiStyleInjection.d.ts +2 -0
- package/dist/hooks/useShikiStyleInjection.d.ts.map +1 -0
- package/dist/hooks/useShikiStyleInjection.js +34 -0
- package/dist/hooks/useShikiStyleInjection.js.map +1 -0
- package/dist/onboarding/sign-in.stories.js +93 -0
- package/dist/onboarding/sign-in.stories.js.map +1 -0
- package/index.css +130 -12
- package/package.json +14 -3
- package/src/assets/illustration-1.svg +92 -0
- package/src/assets/illustration-2.svg +14 -0
- package/src/assets/illustration-gradient.svg +7049 -0
- package/src/components/alert/alert.stories.tsx +2 -2
- package/src/components/alert/alert.tsx +3 -3
- package/src/components/avatar/avatar-group.tsx +3 -3
- package/src/components/avatar/avatar.stories.tsx +9 -2
- package/src/components/avatar/avatar.tsx +10 -6
- package/src/components/badge/badge.stories.tsx +468 -0
- package/src/components/badge/badge.tsx +147 -0
- package/src/components/badge/icon-badge.tsx +43 -0
- package/src/components/badge/index.ts +4 -0
- package/src/components/badge/status-badge.tsx +43 -0
- package/src/components/badge/user-badge.tsx +34 -0
- package/src/components/button/button-link.stories.tsx +86 -0
- package/src/components/button/button-link.tsx +76 -0
- package/src/components/{button.stories.tsx → button/button.stories.tsx} +1 -7
- package/src/components/{button.tsx → button/button.tsx} +9 -7
- package/src/components/button/icon-button.stories.tsx +182 -0
- package/src/components/button/icon-button.tsx +69 -0
- package/src/components/button/index.ts +3 -0
- package/src/components/checkbox/checkbox-label.tsx +125 -0
- package/src/components/checkbox/checkbox-links.tsx +90 -0
- package/src/components/checkbox/checkbox.stories.tsx +375 -0
- package/src/components/checkbox/checkbox.tsx +71 -0
- package/src/components/checkbox/index.ts +3 -0
- package/src/components/code-block/code-block-footer.tsx +173 -0
- package/src/components/code-block/code-block.stories.tsx +323 -0
- package/src/components/code-block/code-block.tsx +283 -0
- package/src/components/code-block/code-content.tsx +63 -0
- package/src/components/code-block/code-copy-button.tsx +73 -0
- package/src/components/code-block/code-tabs.tsx +170 -0
- package/src/components/code-block/index.ts +3 -0
- package/src/components/dynamic-item/dynamic-item.stories.tsx +261 -0
- package/src/components/dynamic-item/dynamic-item.tsx +68 -0
- package/src/components/dynamic-item/index.ts +1 -0
- package/src/components/icon/custom/index.ts +2 -0
- package/src/components/icon/custom/slack-logo.tsx +35 -0
- package/src/components/icon/custom/stripe-logo.tsx +27 -0
- package/src/components/icon/icon.stories.tsx +3 -1
- package/src/components/icon/icon.tsx +23 -1
- package/src/components/index.ts +9 -1
- package/src/components/inline-tips/inline-tips.stories.tsx +3 -3
- package/src/components/inline-tips/inline-tips.tsx +2 -2
- package/src/components/input/index.ts +1 -0
- package/src/components/{input.tsx → input/input.tsx} +1 -1
- package/src/components/item/index.ts +1 -0
- package/src/components/item/item.stories.tsx +150 -0
- package/src/components/item/item.tsx +182 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.stories.tsx +67 -0
- package/src/components/label/label.tsx +15 -0
- package/src/components/moving-border/moving-border.tsx +67 -0
- package/src/components/textarea/textarea.tsx +1 -1
- package/src/components/theme/index.ts +1 -0
- package/src/components/toast/index.ts +2 -0
- package/src/components/toast/toast-custom.tsx +154 -0
- package/src/components/toast/toast.stories.tsx +369 -0
- package/src/components/toast/toast.tsx +41 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/tooltip.stories.tsx +284 -0
- package/src/components/tooltip/tooltip.tsx +79 -10
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useResolvedTheme.ts +34 -0
- package/src/hooks/useShikiHighlight.ts +140 -0
- package/src/hooks/useShikiStyleInjection.ts +34 -0
- package/src/onboarding/sign-in.stories.tsx +73 -0
- package/vitest.config.ts +30 -3
- package/dist/components/button.d.ts.map +0 -1
- package/dist/components/button.js.map +0 -1
- package/dist/components/button.stories.js.map +0 -1
- package/dist/components/input.d.ts.map +0 -1
- package/dist/components/input.js.map +0 -1
- package/dist/components/input.stories.js.map +0 -1
- package/dist/components/theme-provider.d.ts.map +0 -1
- package/dist/components/theme-provider.js.map +0 -1
- /package/dist/components/{input.d.ts → input/input.d.ts} +0 -0
- /package/src/components/{input.stories.tsx → input/input.stories.tsx} +0 -0
- /package/src/components/{theme-provider.tsx → theme/theme-provider.tsx} +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import {useControllableState} from '@radix-ui/react-use-controllable-state';
|
|
2
|
+
import {CodeContent} from 'components/code-block/code-content';
|
|
3
|
+
import {CodeCopyButton} from 'components/code-block/code-copy-button';
|
|
4
|
+
import {useResolvedTheme} from 'hooks/useResolvedTheme';
|
|
5
|
+
import {useShikiHighlight} from 'hooks/useShikiHighlight';
|
|
6
|
+
import {useShikiStyleInjection} from 'hooks/useShikiStyleInjection';
|
|
7
|
+
import type {ComponentProps, HTMLAttributes, ReactNode} from 'react';
|
|
8
|
+
import {createContext, useContext} from 'react';
|
|
9
|
+
import {cn} from 'utils/cn';
|
|
10
|
+
|
|
11
|
+
export type BundledLanguage = string;
|
|
12
|
+
|
|
13
|
+
export type CodeBlockData = {
|
|
14
|
+
language: string;
|
|
15
|
+
filename: string;
|
|
16
|
+
code: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type CodeBlockContextType = {
|
|
20
|
+
value: string | undefined;
|
|
21
|
+
onValueChange: ((value: string) => void) | undefined;
|
|
22
|
+
data: CodeBlockData[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const CodeBlockContext = createContext<CodeBlockContextType>({
|
|
26
|
+
value: undefined,
|
|
27
|
+
onValueChange: undefined,
|
|
28
|
+
data: [],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type CodeBlockProps = HTMLAttributes<HTMLDivElement> & {
|
|
32
|
+
defaultValue?: string;
|
|
33
|
+
value?: string;
|
|
34
|
+
onValueChange?: (value: string) => void;
|
|
35
|
+
data: CodeBlockData[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function CodeBlock({
|
|
39
|
+
value: controlledValue,
|
|
40
|
+
onValueChange: controlledOnValueChange,
|
|
41
|
+
defaultValue,
|
|
42
|
+
className,
|
|
43
|
+
data,
|
|
44
|
+
...props
|
|
45
|
+
}: CodeBlockProps) {
|
|
46
|
+
const [value, onValueChange] = useControllableState({
|
|
47
|
+
defaultProp: defaultValue ?? '',
|
|
48
|
+
prop: controlledValue,
|
|
49
|
+
onChange: controlledOnValueChange,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<CodeBlockContext.Provider value={{value, onValueChange, data}}>
|
|
54
|
+
<div
|
|
55
|
+
className={cn(
|
|
56
|
+
'size-full overflow-hidden rounded-12 bg-background-components-pressed dark:bg-background-contrast-base shadow-button-neutral',
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
</CodeBlockContext.Provider>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type CodeBlockHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
66
|
+
|
|
67
|
+
export function CodeBlockHeader({className, ...props}: CodeBlockHeaderProps) {
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
className={cn(
|
|
71
|
+
'flex w-full flex-row items-center gap-12 overflow-clip bg-background-components-pressed dark:bg-background-contrast-base px-16 py-8',
|
|
72
|
+
className,
|
|
73
|
+
)}
|
|
74
|
+
{...props}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type CodeBlockFilesProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
80
|
+
children: (item: CodeBlockData) => ReactNode;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export function CodeBlockFiles({className, children, ...props}: CodeBlockFilesProps) {
|
|
84
|
+
const {data} = useContext(CodeBlockContext);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div className={cn('flex grow flex-row items-center gap-12', className)} {...props}>
|
|
88
|
+
{data.map((item, index) => (
|
|
89
|
+
<div key={item.language || index}>{children(item)}</div>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type CodeBlockFilenameProps = HTMLAttributes<HTMLDivElement> & {
|
|
96
|
+
value?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export function CodeBlockFilename({className, value, children, ...props}: CodeBlockFilenameProps) {
|
|
100
|
+
const {value: activeValue} = useContext(CodeBlockContext);
|
|
101
|
+
|
|
102
|
+
if (value !== activeValue) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div
|
|
108
|
+
className={cn(
|
|
109
|
+
'flex min-h-0 min-w-0 flex-1 items-center overflow-hidden text-ellipsis whitespace-nowrap text-xs leading-20 font-code text-foreground-neutral-muted',
|
|
110
|
+
className,
|
|
111
|
+
)}
|
|
112
|
+
{...props}
|
|
113
|
+
>
|
|
114
|
+
{children}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type CodeBlockCopyButtonProps = ComponentProps<'button'> & {
|
|
120
|
+
onCopy?: () => void;
|
|
121
|
+
onError?: (error: Error) => void;
|
|
122
|
+
timeout?: number;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function CodeBlockCopyButton({
|
|
126
|
+
onCopy,
|
|
127
|
+
onError,
|
|
128
|
+
timeout = 2000,
|
|
129
|
+
children,
|
|
130
|
+
className,
|
|
131
|
+
...props
|
|
132
|
+
}: CodeBlockCopyButtonProps) {
|
|
133
|
+
const {data, value} = useContext(CodeBlockContext);
|
|
134
|
+
const code = data.find((item) => item.language === value)?.code ?? '';
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<CodeCopyButton
|
|
138
|
+
content={code}
|
|
139
|
+
onCopy={() => onCopy?.()}
|
|
140
|
+
onError={onError}
|
|
141
|
+
timeout={timeout}
|
|
142
|
+
className={className}
|
|
143
|
+
{...props}
|
|
144
|
+
>
|
|
145
|
+
{children}
|
|
146
|
+
</CodeCopyButton>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type CodeBlockFallbackProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
151
|
+
children: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function CodeBlockFallback({children, className, ...props}: CodeBlockFallbackProps) {
|
|
155
|
+
const lines = children?.toString().split('\n') ?? [];
|
|
156
|
+
return (
|
|
157
|
+
<pre
|
|
158
|
+
className={cn('w-full font-code', className)}
|
|
159
|
+
{...(props as HTMLAttributes<HTMLPreElement>)}
|
|
160
|
+
>
|
|
161
|
+
<code>
|
|
162
|
+
{lines.map((line) => {
|
|
163
|
+
const isDiffRemove = line.trim().startsWith('-');
|
|
164
|
+
const isDiffAdd = line.trim().startsWith('+');
|
|
165
|
+
const diffClass = isDiffRemove ? 'diff remove' : isDiffAdd ? 'diff add' : '';
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<span className={cn('line', diffClass)} key={line}>
|
|
169
|
+
{line}
|
|
170
|
+
</span>
|
|
171
|
+
);
|
|
172
|
+
})}
|
|
173
|
+
</code>
|
|
174
|
+
</pre>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type CodeBlockBodyProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
179
|
+
children: (item: CodeBlockData) => ReactNode;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export function CodeBlockBody({children, ...props}: CodeBlockBodyProps) {
|
|
183
|
+
const {data} = useContext(CodeBlockContext);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div {...props}>
|
|
187
|
+
{data.map((item, index) => (
|
|
188
|
+
<div key={item.language || index}>{children(item)}</div>
|
|
189
|
+
))}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type CodeBlockItemProps = HTMLAttributes<HTMLDivElement> & {
|
|
195
|
+
value: string;
|
|
196
|
+
lineNumbers?: boolean;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export function CodeBlockItem({
|
|
200
|
+
children,
|
|
201
|
+
lineNumbers = true,
|
|
202
|
+
className,
|
|
203
|
+
value,
|
|
204
|
+
...props
|
|
205
|
+
}: CodeBlockItemProps) {
|
|
206
|
+
const {value: activeValue} = useContext(CodeBlockContext);
|
|
207
|
+
|
|
208
|
+
if (value !== activeValue) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
className={cn('flex w-full shrink-0 items-start overflow-clip px-4 pb-4 pt-0', className)}
|
|
215
|
+
{...props}
|
|
216
|
+
>
|
|
217
|
+
<div
|
|
218
|
+
className={cn(
|
|
219
|
+
'flex min-h-0 min-w-0 flex-1 shrink-0 rounded-8 border border-border-contrast-bottom bg-background-neutral-base dark:bg-background-contrast-subtle font-code',
|
|
220
|
+
'[&_pre]:py-12 [&_pre]:font-code',
|
|
221
|
+
'[&_code]:w-full [&_code]:grid [&_code]:overflow-x-auto [&_code]:bg-transparent [&_code]:font-code [&_code]:text-xs [&_code]:leading-20 [&_code]:text-foreground-neutral-base',
|
|
222
|
+
'[&_.line]:block [&_.line]:px-12 [&_.line]:w-full [&_.line]:relative [&_.line]:font-code [&_.line]:min-h-[1.25rem]',
|
|
223
|
+
lineNumbers &&
|
|
224
|
+
'[&_code]:[counter-reset:line] [&_code]:[counter-increment:line_0] [&_.line]:before:content-[counter(line)] [&_.line]:before:inline-block [&_.line]:before:[counter-increment:line] [&_.line]:before:w-16 [&_.line]:before:mr-16 [&_.line]:before:text-xs [&_.line]:before:text-right [&_.line]:before:text-foreground-neutral-subtle [&_.line]:before:font-code [&_.line]:before:select-none',
|
|
225
|
+
'[&_.line.diff]:after:absolute [&_.line.diff]:after:left-0 [&_.line.diff]:after:top-0 [&_.line.diff]:after:bottom-0 [&_.line.diff]:after:w-1',
|
|
226
|
+
'[&_.line.diff.add]:bg-emerald-50 [&_.line.diff.add]:text-green-700 [&_.line.diff.add]:after:bg-emerald-500',
|
|
227
|
+
'[&_.line.diff.remove]:bg-rose-50 [&_.line.diff.remove]:text-red-700 [&_.line.diff.remove]:after:bg-rose-500',
|
|
228
|
+
'dark:[&_.line.diff.add]:bg-emerald-500/10 dark:[&_.line.diff.add]:text-emerald-400',
|
|
229
|
+
'dark:[&_.line.diff.remove]:bg-rose-500/10 dark:[&_.line.diff.remove]:text-rose-400',
|
|
230
|
+
)}
|
|
231
|
+
>
|
|
232
|
+
{children}
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export type CodeBlockContentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
239
|
+
themes?: {
|
|
240
|
+
light: string;
|
|
241
|
+
dark: string;
|
|
242
|
+
};
|
|
243
|
+
language?: BundledLanguage;
|
|
244
|
+
syntaxHighlighting?: boolean;
|
|
245
|
+
children: string;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export function CodeBlockContent({
|
|
249
|
+
children,
|
|
250
|
+
themes = {
|
|
251
|
+
light: 'vitesse-light',
|
|
252
|
+
dark: 'vitesse-dark',
|
|
253
|
+
},
|
|
254
|
+
language = 'typescript',
|
|
255
|
+
syntaxHighlighting = false,
|
|
256
|
+
...props
|
|
257
|
+
}: CodeBlockContentProps) {
|
|
258
|
+
const resolvedTheme = useResolvedTheme();
|
|
259
|
+
|
|
260
|
+
useShikiStyleInjection(syntaxHighlighting);
|
|
261
|
+
|
|
262
|
+
const {highlightedCode, isLoading} = useShikiHighlight({
|
|
263
|
+
code: children,
|
|
264
|
+
lang: language,
|
|
265
|
+
themes,
|
|
266
|
+
resolvedTheme,
|
|
267
|
+
syntaxHighlighting,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if (!syntaxHighlighting || isLoading) {
|
|
271
|
+
return <CodeBlockFallback {...props}>{children}</CodeBlockFallback>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<CodeContent
|
|
276
|
+
code={children}
|
|
277
|
+
highlightedCode={highlightedCode}
|
|
278
|
+
isLoading={isLoading}
|
|
279
|
+
syntaxHighlighting={syntaxHighlighting}
|
|
280
|
+
{...props}
|
|
281
|
+
/>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {HTMLAttributes} from 'react';
|
|
2
|
+
import {cn} from 'utils/cn';
|
|
3
|
+
|
|
4
|
+
type CodeContentProps = HTMLAttributes<HTMLElement> & {
|
|
5
|
+
code: string;
|
|
6
|
+
highlightedCode?: string;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
syntaxHighlighting: boolean;
|
|
9
|
+
lineNumbers?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function CodeContent({
|
|
13
|
+
code,
|
|
14
|
+
highlightedCode,
|
|
15
|
+
isLoading,
|
|
16
|
+
syntaxHighlighting,
|
|
17
|
+
lineNumbers = false,
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}: CodeContentProps) {
|
|
21
|
+
const shouldShowHighlighted = syntaxHighlighting && !isLoading && highlightedCode;
|
|
22
|
+
|
|
23
|
+
if (shouldShowHighlighted) {
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
className={cn(
|
|
27
|
+
'shiki-override w-full overflow-x-auto font-code [&_pre]:m-0 [&_pre]:p-0 [&_pre]:bg-transparent [&_pre]:font-code [&_code]:font-code [&_code]:bg-transparent [&_code]:text-xs [&_code]:leading-20 [&_code]:text-foreground-neutral-base [&_code]:grid',
|
|
28
|
+
lineNumbers &&
|
|
29
|
+
'[&_code]:[counter-reset:line] [&_code]:[counter-increment:line_0] [&_.line]:before:content-[counter(line)] [&_.line]:before:inline-block [&_.line]:before:[counter-increment:line] [&_.line]:before:w-16 [&_.line]:before:mr-16 [&_.line]:before:text-xs [&_.line]:before:text-right [&_.line]:before:text-foreground-neutral-subtle [&_.line]:before:font-code [&_.line]:before:select-none',
|
|
30
|
+
'[&_.line]:block [&_.line]:px-12 [&_.line]:w-full [&_.line]:relative [&_.line]:font-code [&_.line]:text-xs [&_.line]:leading-20 [&_.line]:min-h-[1.25rem]',
|
|
31
|
+
className,
|
|
32
|
+
)}
|
|
33
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: Shiki outputs HTML for syntax highlighting
|
|
34
|
+
dangerouslySetInnerHTML={{__html: highlightedCode}}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const lines = code.split('\n');
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<pre className={cn('m-0 p-0 bg-transparent font-code', className)} {...props}>
|
|
44
|
+
<code
|
|
45
|
+
className={cn(
|
|
46
|
+
'w-full overflow-x-auto bg-transparent font-code text-xs leading-20 text-foreground-neutral-base',
|
|
47
|
+
'grid',
|
|
48
|
+
lineNumbers &&
|
|
49
|
+
'[counter-reset:line] [counter-increment:line_0] [&_.line]:before:content-[counter(line)] [&_.line]:before:inline-block [&_.line]:before:[counter-increment:line] [&_.line]:before:w-16 [&_.line]:before:mr-16 [&_.line]:before:text-xs [&_.line]:before:text-right [&_.line]:before:text-foreground-neutral-subtle [&_.line]:before:font-code [&_.line]:before:select-none',
|
|
50
|
+
)}
|
|
51
|
+
>
|
|
52
|
+
{lines.map((line, index) => (
|
|
53
|
+
<span
|
|
54
|
+
className="line px-12 w-full relative font-code text-xs leading-20"
|
|
55
|
+
key={`${index}-${line}`}
|
|
56
|
+
>
|
|
57
|
+
{line}
|
|
58
|
+
</span>
|
|
59
|
+
))}
|
|
60
|
+
</code>
|
|
61
|
+
</pre>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {Icon} from 'components/icon';
|
|
2
|
+
import {useCopyToClipboard} from 'hooks/useCopyToClipboard';
|
|
3
|
+
import type {ComponentProps} from 'react';
|
|
4
|
+
import {useEffect, useRef, useState} from 'react';
|
|
5
|
+
import {cn} from 'utils/cn';
|
|
6
|
+
|
|
7
|
+
type CodeCopyButtonProps = Omit<ComponentProps<'button'>, 'onCopy'> & {
|
|
8
|
+
content: string;
|
|
9
|
+
onCopy?: (content: string) => void;
|
|
10
|
+
onError?: (error: Error) => void;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function CodeCopyButton({
|
|
16
|
+
content,
|
|
17
|
+
onCopy,
|
|
18
|
+
onError,
|
|
19
|
+
timeout = 2000,
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
...props
|
|
23
|
+
}: CodeCopyButtonProps) {
|
|
24
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
25
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
26
|
+
|
|
27
|
+
const {copy} = useCopyToClipboard({
|
|
28
|
+
text: content,
|
|
29
|
+
onCopy: () => {
|
|
30
|
+
setIsCopied(true);
|
|
31
|
+
onCopy?.(content);
|
|
32
|
+
|
|
33
|
+
if (timeoutRef.current) {
|
|
34
|
+
clearTimeout(timeoutRef.current);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
timeoutRef.current = setTimeout(() => {
|
|
38
|
+
setIsCopied(false);
|
|
39
|
+
}, timeout);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
return () => {
|
|
45
|
+
if (timeoutRef.current) {
|
|
46
|
+
clearTimeout(timeoutRef.current);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const handleClick = async () => {
|
|
52
|
+
try {
|
|
53
|
+
await copy();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
onError?.(error instanceof Error ? error : new Error('Failed to copy'));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
aria-label={isCopied ? 'Copied' : 'Copy to clipboard'}
|
|
63
|
+
className={cn(
|
|
64
|
+
'flex shrink-0 cursor-pointer items-center justify-center rounded-6 bg-transparent text-foreground-neutral-muted transition-colors hover:bg-background-components-hover active:bg-background-components-pressed p-4',
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
onClick={handleClick}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
{children ?? <Icon name={isCopied ? 'check' : 'copy'} className="size-16" />}
|
|
71
|
+
</button>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as Tabs from '@radix-ui/react-tabs';
|
|
2
|
+
import {useControllableState} from '@radix-ui/react-use-controllable-state';
|
|
3
|
+
import {CodeContent} from 'components/code-block/code-content';
|
|
4
|
+
import {CodeCopyButton} from 'components/code-block/code-copy-button';
|
|
5
|
+
import {useResolvedTheme} from 'hooks/useResolvedTheme';
|
|
6
|
+
import {useShikiHighlightMultiple} from 'hooks/useShikiHighlight';
|
|
7
|
+
import {useShikiStyleInjection} from 'hooks/useShikiStyleInjection';
|
|
8
|
+
import type {ComponentProps} from 'react';
|
|
9
|
+
import {useMemo} from 'react';
|
|
10
|
+
import {cn} from 'utils/cn';
|
|
11
|
+
|
|
12
|
+
export type CodeTabsProps = Omit<ComponentProps<typeof Tabs.Root>, 'children'> & {
|
|
13
|
+
codes: Record<string, string>;
|
|
14
|
+
lang?: string;
|
|
15
|
+
themes?: {
|
|
16
|
+
light: string;
|
|
17
|
+
dark: string;
|
|
18
|
+
};
|
|
19
|
+
copyButton?: boolean;
|
|
20
|
+
onCopy?: (content: string) => void;
|
|
21
|
+
syntaxHighlighting?: boolean;
|
|
22
|
+
lineNumbers?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function CodeTabsContent({
|
|
26
|
+
codes,
|
|
27
|
+
lang = 'bash',
|
|
28
|
+
themes = {
|
|
29
|
+
light: 'vitesse-light',
|
|
30
|
+
dark: 'vitesse-dark',
|
|
31
|
+
},
|
|
32
|
+
copyButton = true,
|
|
33
|
+
onCopy,
|
|
34
|
+
syntaxHighlighting = false,
|
|
35
|
+
lineNumbers = false,
|
|
36
|
+
activeValue,
|
|
37
|
+
}: {
|
|
38
|
+
codes: Record<string, string>;
|
|
39
|
+
lang?: string;
|
|
40
|
+
themes?: {light: string; dark: string};
|
|
41
|
+
copyButton?: boolean;
|
|
42
|
+
onCopy?: (content: string) => void;
|
|
43
|
+
syntaxHighlighting?: boolean;
|
|
44
|
+
lineNumbers?: boolean;
|
|
45
|
+
activeValue: string;
|
|
46
|
+
}) {
|
|
47
|
+
const resolvedTheme = useResolvedTheme();
|
|
48
|
+
const codesKeys = useMemo(() => Object.keys(codes), [codes]);
|
|
49
|
+
|
|
50
|
+
useShikiStyleInjection(syntaxHighlighting);
|
|
51
|
+
|
|
52
|
+
const {highlightedCodes, isLoading} = useShikiHighlightMultiple({
|
|
53
|
+
codes,
|
|
54
|
+
lang,
|
|
55
|
+
themes,
|
|
56
|
+
resolvedTheme,
|
|
57
|
+
syntaxHighlighting,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const activeCode = codes[activeValue] ?? '';
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
<Tabs.List
|
|
65
|
+
className={cn(
|
|
66
|
+
'relative flex w-full flex-row items-center justify-between gap-12 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden bg-background-components-pressed dark:bg-background-contrast-base px-16 py-8',
|
|
67
|
+
'border-b border-border-contrast-bottom',
|
|
68
|
+
'after:absolute after:bottom-0 after:left-0 after:right-0 after:h-px',
|
|
69
|
+
'after:bg-border-neutral-base',
|
|
70
|
+
'dark:after:bg-border-contrast-top',
|
|
71
|
+
'after:shadow-separator-inset',
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
<div className="flex flex-row gap-12">
|
|
75
|
+
{codesKeys.map((code) => (
|
|
76
|
+
<Tabs.Trigger
|
|
77
|
+
key={code}
|
|
78
|
+
value={code}
|
|
79
|
+
className={cn(
|
|
80
|
+
'relative px-8 py-4 text-xs leading-20 font-medium text-foreground-neutral-muted transition-colors',
|
|
81
|
+
'data-[state=active]:text-foreground-neutral-base',
|
|
82
|
+
'hover:text-foreground-neutral-base',
|
|
83
|
+
'data-[state=active]:z-10',
|
|
84
|
+
'data-[state=active]:after:absolute data-[state=active]:after:-bottom-9 data-[state=active]:after:left-0 data-[state=active]:after:right-0',
|
|
85
|
+
'data-[state=active]:after:h-2 data-[state=active]:after:bg-foreground-neutral-base',
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
{code}
|
|
89
|
+
</Tabs.Trigger>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
{copyButton && <CodeCopyButton content={activeCode} onCopy={onCopy} className="shrink-0" />}
|
|
94
|
+
</Tabs.List>
|
|
95
|
+
<div className="w-full px-4 pb-4 pt-8">
|
|
96
|
+
{Object.entries(codes).map(([code, rawCode]) => (
|
|
97
|
+
<Tabs.Content key={code} value={code} className="w-full">
|
|
98
|
+
<div
|
|
99
|
+
className={cn(
|
|
100
|
+
'flex min-h-0 min-w-0 w-full shrink-0 rounded-8 border border-border-contrast-bottom bg-background-neutral-base dark:bg-background-contrast-subtle font-code',
|
|
101
|
+
'[&_pre]:py-12 [&_pre]:font-code',
|
|
102
|
+
'[&_pre]:m-0 [&_pre]:px-0 [&_pre]:bg-transparent',
|
|
103
|
+
'[&_code]:w-full [&_code]:overflow-x-auto [&_code]:bg-transparent [&_code]:font-code [&_code]:text-xs [&_code]:leading-20 [&_code]:text-foreground-neutral-base',
|
|
104
|
+
lineNumbers &&
|
|
105
|
+
'[&_code]:grid [&_code]:[counter-reset:line] [&_code]:[counter-increment:line_0] [&_.line]:before:content-[counter(line)] [&_.line]:before:inline-block [&_.line]:before:[counter-increment:line] [&_.line]:before:w-16 [&_.line]:before:mr-16 [&_.line]:before:text-xs [&_.line]:before:text-right [&_.line]:before:text-foreground-neutral-subtle [&_.line]:before:font-code [&_.line]:before:select-none',
|
|
106
|
+
'[&_.line]:block [&_.line]:px-12 [&_.line]:w-full [&_.line]:relative [&_.line]:font-code [&_.line]:min-h-[1.25rem]',
|
|
107
|
+
)}
|
|
108
|
+
>
|
|
109
|
+
<CodeContent
|
|
110
|
+
code={rawCode}
|
|
111
|
+
highlightedCode={highlightedCodes[code]}
|
|
112
|
+
isLoading={isLoading}
|
|
113
|
+
syntaxHighlighting={syntaxHighlighting}
|
|
114
|
+
lineNumbers={lineNumbers}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
</Tabs.Content>
|
|
118
|
+
))}
|
|
119
|
+
</div>
|
|
120
|
+
</>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function CodeTabs({
|
|
125
|
+
codes,
|
|
126
|
+
lang = 'bash',
|
|
127
|
+
themes = {
|
|
128
|
+
light: 'vitesse-light',
|
|
129
|
+
dark: 'vitesse-dark',
|
|
130
|
+
},
|
|
131
|
+
className,
|
|
132
|
+
defaultValue,
|
|
133
|
+
value: controlledValue,
|
|
134
|
+
onValueChange: controlledOnValueChange,
|
|
135
|
+
copyButton = true,
|
|
136
|
+
onCopy,
|
|
137
|
+
syntaxHighlighting = false,
|
|
138
|
+
lineNumbers = false,
|
|
139
|
+
...props
|
|
140
|
+
}: CodeTabsProps) {
|
|
141
|
+
const firstKey = useMemo(() => Object.keys(codes)[0] ?? '', [codes]);
|
|
142
|
+
const [value, onValueChange] = useControllableState({
|
|
143
|
+
defaultProp: defaultValue ?? firstKey,
|
|
144
|
+
prop: controlledValue,
|
|
145
|
+
onChange: controlledOnValueChange,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<Tabs.Root
|
|
150
|
+
className={cn(
|
|
151
|
+
'w-full overflow-hidden rounded-12 bg-background-components-pressed dark:bg-background-contrast-base shadow-button-neutral',
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
value={value}
|
|
155
|
+
onValueChange={onValueChange}
|
|
156
|
+
{...props}
|
|
157
|
+
>
|
|
158
|
+
<CodeTabsContent
|
|
159
|
+
codes={codes}
|
|
160
|
+
lang={lang}
|
|
161
|
+
themes={themes}
|
|
162
|
+
copyButton={copyButton}
|
|
163
|
+
onCopy={onCopy}
|
|
164
|
+
syntaxHighlighting={syntaxHighlighting}
|
|
165
|
+
lineNumbers={lineNumbers}
|
|
166
|
+
activeValue={value ?? firstKey}
|
|
167
|
+
/>
|
|
168
|
+
</Tabs.Root>
|
|
169
|
+
);
|
|
170
|
+
}
|