@juspay/blend-design-system 0.0.37-beta.3 → 0.0.37-beta.5
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/AccordionV2/index.d.ts +3 -0
- package/dist/components/AvatarV2/avatarV2.utils.d.ts +1 -1
- package/dist/components/AvatarV2/index.d.ts +1 -2
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +2 -5
- package/dist/components/Breadcrumb/types.d.ts +6 -0
- package/dist/components/BreadcrumbV2/index.d.ts +10 -0
- package/dist/components/ButtonV2/ButtonGroupV2/index.d.ts +1 -0
- package/dist/components/ButtonV2/buttonV2.types.d.ts +0 -4
- package/dist/components/ButtonV2/index.d.ts +3 -0
- package/dist/components/ButtonV2/utils.d.ts +1 -1
- package/dist/components/Charts/ChartUtils.d.ts +2 -0
- package/dist/components/Charts/types.d.ts +2 -2
- package/dist/components/ChartsV2/index.d.ts +5 -0
- package/dist/components/CodeEditorV2/CodeEditorV2.d.ts +1 -1
- package/dist/components/CodeEditorV2/codeEditorV2.tokens.d.ts +5 -5
- package/dist/components/CodeEditorV2/codeEditorV2.types.d.ts +5 -5
- package/dist/components/CodeEditorV2/index.d.ts +2 -0
- package/dist/components/CodeEditorV2/utils.d.ts +1 -1
- package/dist/components/DataTable/DataTable.d.ts +2 -1
- package/dist/components/DataTable/PivotTableModal/PivotPreviewPanel.d.ts +3 -0
- package/dist/components/DataTable/PivotTableModal/PivotTableIllustration.d.ts +7 -0
- package/dist/components/DataTable/PivotTableModal/index.d.ts +3 -0
- package/dist/components/DataTable/PivotTableModal/pivotModalStyleTokens.d.ts +123 -0
- package/dist/components/DataTable/PivotTableModal/types.d.ts +62 -0
- package/dist/components/DataTable/PivotTableModal/utils.d.ts +32 -0
- package/dist/components/DataTable/TableBody/types.d.ts +2 -0
- package/dist/components/DataTable/TableHeader/types.d.ts +1 -0
- package/dist/components/DataTable/index.d.ts +2 -0
- package/dist/components/DataTable/types.d.ts +56 -0
- package/dist/components/DataTable/utils.d.ts +19 -1
- package/dist/components/DateRangePicker/types.d.ts +1 -1
- package/dist/components/DateRangePicker/utils.d.ts +2 -0
- package/dist/components/Directory/Directory.d.ts +1 -1
- package/dist/components/Directory/types.d.ts +1 -1
- package/dist/components/Directory/utils.d.ts +2 -0
- package/dist/components/InputsV2/ChatInputV2/AttachmentDropdown.d.ts +3 -3
- package/dist/components/InputsV2/ChatInputV2/ChatInputTagV2.d.ts +2 -2
- package/dist/components/InputsV2/ChatInputV2/ChatInputV2.d.ts +4 -4
- package/dist/components/InputsV2/ChatInputV2/ChatInputV2.types.d.ts +8 -8
- package/dist/components/InputsV2/ChatInputV2/ChatInputV2AttachmentRow.d.ts +3 -3
- package/dist/components/InputsV2/ChatInputV2/MobileChatInputV2.d.ts +2 -2
- package/dist/components/InputsV2/ChatInputV2/utils.d.ts +4 -4
- package/dist/components/InputsV2/SearchInputV2/utils.d.ts +39 -0
- package/dist/components/InputsV2/TextInputV2/TextInputV2.types.d.ts +2 -2
- package/dist/components/InputsV2/TextInputV2/index.d.ts +2 -0
- package/dist/components/InputsV2/utils/utils.d.ts +1 -1
- package/dist/components/KeyValuePairV2/KeyValuePairV2.d.ts +1 -1
- package/dist/components/KeyValuePairV2/ResponsiveText.d.ts +2 -2
- package/dist/components/KeyValuePairV2/index.d.ts +3 -0
- package/dist/components/KeyValuePairV2/keyValuePairV2.types.d.ts +2 -2
- package/dist/components/KeyValuePairV2/responsiveTextStyles.d.ts +3 -3
- package/dist/components/KeyValuePairV2/utils.d.ts +2 -2
- package/dist/components/MenuV2/index.d.ts +1 -0
- package/dist/components/MenuV2/menuV2.utils.d.ts +2 -2
- package/dist/components/MultiSelectV2/index.d.ts +3 -0
- package/dist/components/MultiSelectV2/multiSelectV2.types.d.ts +1 -1
- package/dist/components/MultiSelectV2/utils.d.ts +2 -2
- package/dist/components/ProgressBarV2/index.d.ts +3 -0
- package/dist/components/ProgressBarV2/utils.d.ts +1 -1
- package/dist/components/Radio/StyledRadio.d.ts +0 -1
- package/dist/components/SelectV2/index.d.ts +1 -0
- package/dist/components/SelectorV2/CheckboxV2/index.d.ts +4 -0
- package/dist/components/SelectorV2/CheckboxV2/utils.d.ts +1 -1
- package/dist/components/SelectorV2/RadioV2/index.d.ts +3 -0
- package/dist/components/SelectorV2/SwitchV2/index.d.ts +1 -0
- package/dist/components/Sidebar/SidebarContent.d.ts +1 -1
- package/dist/components/Sidebar/types.d.ts +10 -1
- package/dist/components/Sidebar/utils.d.ts +1 -1
- package/dist/components/SidebarV2/SidebarV2Panel.d.ts +1 -1
- package/dist/components/SidebarV2/index.d.ts +6 -1
- package/dist/components/SidebarV2/types.d.ts +3 -0
- package/dist/components/SingleSelectV2/SingleSelectV2VirtualList.d.ts +2 -2
- package/dist/components/SingleSelectV2/index.d.ts +3 -0
- package/dist/components/SingleSelectV2/singleSelectV2.types.d.ts +2 -2
- package/dist/components/SingleSelectV2/utils.d.ts +6 -6
- package/dist/components/StatCardV2/index.d.ts +10 -1
- package/dist/components/Stepper/types.d.ts +2 -0
- package/dist/components/StepperV2/index.d.ts +3 -1
- package/dist/components/StepperV2/stepperV2.types.d.ts +2 -2
- package/dist/components/TabsV2/index.d.ts +3 -1
- package/dist/components/TagV2/index.d.ts +3 -0
- package/dist/components/TooltipV2/index.d.ts +1 -0
- package/dist/components/common/index.d.ts +1 -1
- package/dist/main.d.ts +30 -70
- package/dist/main.js +91851 -89103
- package/dist/{node-CRWdZOVN.js → node-C2uf3sNA.js} +1303 -1300
- package/dist/node.js +1 -1
- package/dist/tokens.js +17 -16
- package/lib/components/AccordionV2/index.ts +3 -0
- package/lib/components/Avatar/Avatar.tsx +6 -1
- package/lib/components/AvatarGroup/AvatarGroup.tsx +1 -1
- package/lib/components/AvatarV2/AvatarV2.tsx +12 -3
- package/lib/components/AvatarV2/avatarV2.utils.ts +1 -1
- package/lib/components/AvatarV2/index.ts +1 -12
- package/lib/components/Breadcrumb/Breadcrumb.tsx +9 -8
- package/lib/components/Breadcrumb/types.ts +12 -0
- package/lib/components/BreadcrumbV2/index.ts +10 -0
- package/lib/components/Button/ButtonBase.tsx +1 -1
- package/lib/components/ButtonV2/ButtonGroupV2/index.ts +1 -0
- package/lib/components/ButtonV2/ButtonV2.tsx +2 -2
- package/lib/components/ButtonV2/LinkButton.tsx +2 -2
- package/lib/components/ButtonV2/buttonV2.types.ts +0 -6
- package/lib/components/ButtonV2/index.ts +3 -0
- package/lib/components/ButtonV2/utils.ts +2 -2
- package/lib/components/Card/CardComponents.tsx +52 -17
- package/lib/components/Charts/BlendChart.tsx +1 -1
- package/lib/components/Charts/ChartUtils.tsx +7 -0
- package/lib/components/Charts/Charts.tsx +4 -2
- package/lib/components/Charts/CoreChart.tsx +4 -2
- package/lib/components/Charts/types.tsx +2 -2
- package/lib/components/ChartsV2/ChartV2.tsx +4 -3
- package/lib/components/ChartsV2/index.ts +5 -0
- package/lib/components/Checkbox/Checkbox.tsx +29 -7
- package/lib/components/CodeBlock/CodeBlock.tsx +47 -1
- package/lib/components/CodeBlock/codeBlock.token.ts +5 -5
- package/lib/components/CodeEditor/CodeEditor.tsx +26 -4
- package/lib/components/CodeEditor/MonacoEditorWrapper.tsx +13 -1
- package/lib/components/CodeEditorV2/CodeEditorV2.tsx +2 -2
- package/lib/components/CodeEditorV2/codeEditorV2.dark.tokens.ts +37 -25
- package/lib/components/CodeEditorV2/codeEditorV2.light.token.ts +37 -25
- package/lib/components/CodeEditorV2/codeEditorV2.tokens.ts +5 -5
- package/lib/components/CodeEditorV2/codeEditorV2.types.ts +5 -5
- package/lib/components/CodeEditorV2/index.ts +2 -0
- package/lib/components/CodeEditorV2/utils.ts +1 -1
- package/lib/components/DataTable/DataTable.tsx +156 -4
- package/lib/components/DataTable/PivotTableModal/PivotPreviewPanel.tsx +174 -0
- package/lib/components/DataTable/PivotTableModal/PivotTableIllustration.tsx +28 -0
- package/lib/components/DataTable/PivotTableModal/index.tsx +859 -0
- package/lib/components/DataTable/PivotTableModal/pivot-table-illustration.png +0 -0
- package/lib/components/DataTable/PivotTableModal/pivotModal.styled.ts +13 -0
- package/lib/components/DataTable/PivotTableModal/pivotModalStyleTokens.ts +250 -0
- package/lib/components/DataTable/PivotTableModal/types.ts +69 -0
- package/lib/components/DataTable/PivotTableModal/utils.ts +360 -0
- package/lib/components/DataTable/TableBody/index.tsx +16 -5
- package/lib/components/DataTable/TableBody/types.ts +2 -0
- package/lib/components/DataTable/TableHeader/FilterComponents.tsx +4 -0
- package/lib/components/DataTable/TableHeader/index.tsx +6 -3
- package/lib/components/DataTable/TableHeader/types.ts +1 -0
- package/lib/components/DataTable/index.ts +4 -0
- package/lib/components/DataTable/types.ts +57 -0
- package/lib/components/DataTable/utils.ts +197 -0
- package/lib/components/DateRangePicker/DateRangePicker.tsx +34 -17
- package/lib/components/DateRangePicker/types.ts +5 -5
- package/lib/components/DateRangePicker/utils.ts +5 -0
- package/lib/components/Directory/Directory.tsx +3 -2
- package/lib/components/Directory/types.ts +1 -1
- package/lib/components/Directory/utils.ts +6 -0
- package/lib/components/Drawer/components/DrawerBase.tsx +16 -0
- package/lib/components/Drawer/components/NestedSelectDrawer.tsx +13 -1
- package/lib/components/Drawer/components/SelectDrawer.tsx +9 -1
- package/lib/components/Inputs/OTPInput/OTPInput.tsx +5 -3
- package/lib/components/InputsV2/ChatInputV2/AttachmentDropdown.tsx +3 -3
- package/lib/components/InputsV2/ChatInputV2/ChatInputTagV2.tsx +3 -3
- package/lib/components/InputsV2/ChatInputV2/ChatInputV2.types.ts +8 -8
- package/lib/components/InputsV2/ChatInputV2/ChatInputV2AttachmentRow.tsx +7 -7
- package/lib/components/InputsV2/ChatInputV2/utils.ts +8 -8
- package/lib/components/InputsV2/SearchInputV2/utils.ts +14 -1
- package/lib/components/InputsV2/TextInputV2/TextInputV2.tsx +3 -3
- package/lib/components/InputsV2/TextInputV2/TextInputV2.types.ts +2 -2
- package/lib/components/InputsV2/TextInputV2/index.ts +2 -0
- package/lib/components/KeyValuePairV2/KeyValuePairV2.tsx +6 -2
- package/lib/components/KeyValuePairV2/ResponsiveText.tsx +2 -2
- package/lib/components/KeyValuePairV2/index.ts +3 -0
- package/lib/components/KeyValuePairV2/keyValuePairV2.types.ts +2 -2
- package/lib/components/KeyValuePairV2/responsiveTextStyles.ts +3 -3
- package/lib/components/KeyValuePairV2/utils.ts +3 -3
- package/lib/components/Menu/Menu.tsx +9 -1
- package/lib/components/MenuV2/MenuV2.tsx +2 -2
- package/lib/components/MenuV2/MenuV2SubMenu.tsx +2 -2
- package/lib/components/MenuV2/index.ts +1 -0
- package/lib/components/MenuV2/menuV2.utils.ts +4 -4
- package/lib/components/Modal/useModal.ts +7 -0
- package/lib/components/MultiSelectV2/MultiSelectV2.tsx +2 -2
- package/lib/components/MultiSelectV2/MultiSelectV2Menu.tsx +5 -2
- package/lib/components/MultiSelectV2/index.ts +3 -0
- package/lib/components/MultiSelectV2/mobile/MobileMultiSelectV2.tsx +7 -4
- package/lib/components/MultiSelectV2/multiSelectV2.types.ts +1 -1
- package/lib/components/MultiSelectV2/utils.ts +2 -2
- package/lib/components/ProgressBarV2/ProgressBarV2.tsx +5 -2
- package/lib/components/ProgressBarV2/index.ts +3 -0
- package/lib/components/ProgressBarV2/utils.ts +1 -1
- package/lib/components/Radio/Radio.tsx +12 -5
- package/lib/components/Radio/StyledRadio.tsx +33 -17
- package/lib/components/SelectV2/index.ts +1 -0
- package/lib/components/SelectorV2/CheckboxV2/CheckboxV2.tsx +2 -2
- package/lib/components/SelectorV2/CheckboxV2/index.ts +4 -0
- package/lib/components/SelectorV2/CheckboxV2/utils.ts +1 -1
- package/lib/components/SelectorV2/RadioV2/index.ts +3 -0
- package/lib/components/SelectorV2/SwitchV2/index.ts +1 -0
- package/lib/components/Sidebar/Sidebar.tsx +18 -3
- package/lib/components/Sidebar/SidebarContent.tsx +5 -2
- package/lib/components/Sidebar/TenantPanel.tsx +52 -34
- package/lib/components/Sidebar/types.ts +11 -1
- package/lib/components/Sidebar/utils.ts +1 -1
- package/lib/components/SidebarV2/SecondarySidebar.tsx +86 -44
- package/lib/components/SidebarV2/SidebarV2Panel.tsx +4 -2
- package/lib/components/SidebarV2/index.ts +6 -0
- package/lib/components/SidebarV2/types.ts +4 -0
- package/lib/components/SingleSelectV2/MobileSingleSelectV2.tsx +2 -2
- package/lib/components/SingleSelectV2/SingleSelectV2.tsx +10 -3
- package/lib/components/SingleSelectV2/SingleSelectV2Menu.tsx +4 -2
- package/lib/components/SingleSelectV2/SingleSelectV2VirtualList.tsx +5 -2
- package/lib/components/SingleSelectV2/index.ts +7 -0
- package/lib/components/SingleSelectV2/singleSelectV2.types.ts +2 -2
- package/lib/components/SingleSelectV2/utils.ts +10 -10
- package/lib/components/StatCard/statcard.tokens.ts +1 -1
- package/lib/components/StatCardV2/index.ts +13 -1
- package/lib/components/Stepper/VerticalStepper.tsx +209 -171
- package/lib/components/Stepper/types.ts +2 -0
- package/lib/components/StepperV2/Stepper/Steps.tsx +15 -1
- package/lib/components/StepperV2/index.ts +3 -1
- package/lib/components/StepperV2/stepperV2.types.ts +2 -2
- package/lib/components/TabsV2/index.ts +13 -1
- package/lib/components/TagV2/index.ts +3 -0
- package/lib/components/Text/Text.tsx +1 -0
- package/lib/components/TooltipV2/index.ts +1 -0
- package/lib/components/Upload/Upload.tsx +6 -0
- package/lib/components/Upload/components/FileListDisplay.tsx +159 -16
- package/lib/components/Upload/utils.ts +10 -2
- package/lib/components/common/index.ts +1 -1
- package/lib/context/ThemeProvider.tsx +19 -8
- package/lib/hooks/useDebounce.ts +9 -1
- package/lib/main.ts +34 -258
- package/lib/types/assets.d.ts +24 -0
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useId } from 'react'
|
|
1
|
+
import { forwardRef, useEffect, useId, useState } from 'react'
|
|
2
2
|
import { Check, Minus } from 'lucide-react'
|
|
3
3
|
import type { CheckboxProps } from './types'
|
|
4
4
|
import { CheckboxSize } from './types'
|
|
@@ -46,6 +46,26 @@ export const Checkbox = forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
|
46
46
|
const generatedId = useId()
|
|
47
47
|
const uniqueId = id || generatedId
|
|
48
48
|
const shouldShake = useErrorShake(error)
|
|
49
|
+
const isControlled = checked !== undefined
|
|
50
|
+
const [uncontrolledChecked, setUncontrolledChecked] = useState<
|
|
51
|
+
boolean | 'indeterminate'
|
|
52
|
+
>(defaultChecked ?? false)
|
|
53
|
+
const resolvedChecked = isControlled ? checked : uncontrolledChecked
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!isControlled) {
|
|
57
|
+
setUncontrolledChecked(defaultChecked ?? false)
|
|
58
|
+
}
|
|
59
|
+
}, [defaultChecked, isControlled])
|
|
60
|
+
|
|
61
|
+
const handleCheckedChange = (
|
|
62
|
+
nextChecked: boolean | 'indeterminate'
|
|
63
|
+
) => {
|
|
64
|
+
if (!isControlled) {
|
|
65
|
+
setUncontrolledChecked(nextChecked)
|
|
66
|
+
}
|
|
67
|
+
onCheckedChange?.(nextChecked)
|
|
68
|
+
}
|
|
49
69
|
|
|
50
70
|
const labelMaxLength = maxLength?.label
|
|
51
71
|
const subtextMaxLength = maxLength?.subtext
|
|
@@ -76,28 +96,30 @@ export const Checkbox = forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
|
76
96
|
id={uniqueId}
|
|
77
97
|
name={name}
|
|
78
98
|
ref={ref}
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
{...(isControlled
|
|
100
|
+
? { checked }
|
|
101
|
+
: { defaultChecked: defaultChecked ?? false })}
|
|
102
|
+
onCheckedChange={handleCheckedChange}
|
|
81
103
|
disabled={disabled}
|
|
82
104
|
required={required}
|
|
83
105
|
size={size}
|
|
84
106
|
$isDisabled={disabled}
|
|
85
|
-
$checked={
|
|
107
|
+
$checked={resolvedChecked}
|
|
86
108
|
$error={error}
|
|
87
109
|
style={getErrorShakeStyle(shouldShake)}
|
|
88
110
|
{...ariaAttributes}
|
|
89
111
|
{...restProps}
|
|
90
112
|
data-element="checkbox"
|
|
91
113
|
data-state={
|
|
92
|
-
|
|
114
|
+
resolvedChecked === 'indeterminate'
|
|
93
115
|
? 'indeterminate'
|
|
94
|
-
:
|
|
116
|
+
: resolvedChecked
|
|
95
117
|
? 'checked'
|
|
96
118
|
: 'unchecked'
|
|
97
119
|
}
|
|
98
120
|
>
|
|
99
121
|
<CheckboxIndicator
|
|
100
|
-
checked={
|
|
122
|
+
checked={resolvedChecked}
|
|
101
123
|
size={size}
|
|
102
124
|
tokens={tokens}
|
|
103
125
|
disabled={disabled}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useCallback,
|
|
8
8
|
useMemo,
|
|
9
9
|
} from 'react'
|
|
10
|
+
import styled from 'styled-components'
|
|
10
11
|
import { Check, Copy, FileCode } from 'lucide-react'
|
|
11
12
|
import Block from '../Primitives/Block/Block'
|
|
12
13
|
import Button from '../Button/Button'
|
|
@@ -33,6 +34,21 @@ import {
|
|
|
33
34
|
buildDiffViewSegments,
|
|
34
35
|
} from './utils'
|
|
35
36
|
|
|
37
|
+
const CopyOverlay = styled.div`
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: 12px;
|
|
40
|
+
right: 12px;
|
|
41
|
+
z-index: 10;
|
|
42
|
+
opacity: 0;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
transition: opacity 0.15s ease;
|
|
45
|
+
|
|
46
|
+
.code-body:hover & {
|
|
47
|
+
opacity: 1;
|
|
48
|
+
pointer-events: auto;
|
|
49
|
+
}
|
|
50
|
+
`
|
|
51
|
+
|
|
36
52
|
const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
|
|
37
53
|
(
|
|
38
54
|
{
|
|
@@ -255,7 +271,7 @@ const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
|
|
|
255
271
|
type="button"
|
|
256
272
|
onClick={copyToClipboard}
|
|
257
273
|
buttonType={ButtonType.SECONDARY}
|
|
258
|
-
subType={ButtonSubType.
|
|
274
|
+
subType={ButtonSubType.INLINE}
|
|
259
275
|
size={ButtonSize.SMALL}
|
|
260
276
|
aria-label={
|
|
261
277
|
isCopied
|
|
@@ -284,8 +300,38 @@ const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(
|
|
|
284
300
|
}
|
|
285
301
|
backgroundColor={tokens.body.backgroundColor}
|
|
286
302
|
overflow="auto"
|
|
303
|
+
position={
|
|
304
|
+
!showHeader && showCopyButton ? 'relative' : undefined
|
|
305
|
+
}
|
|
306
|
+
className={
|
|
307
|
+
!showHeader && showCopyButton ? 'code-body' : undefined
|
|
308
|
+
}
|
|
287
309
|
style={{ maxHeight: maxHeight || 'none' }}
|
|
288
310
|
>
|
|
311
|
+
{!showHeader && showCopyButton && (
|
|
312
|
+
<CopyOverlay>
|
|
313
|
+
<Button
|
|
314
|
+
data-element="copy-button"
|
|
315
|
+
type="button"
|
|
316
|
+
onClick={copyToClipboard}
|
|
317
|
+
buttonType={ButtonType.SECONDARY}
|
|
318
|
+
subType={ButtonSubType.ICON_ONLY}
|
|
319
|
+
size={ButtonSize.SMALL}
|
|
320
|
+
aria-label={
|
|
321
|
+
isCopied
|
|
322
|
+
? 'Code copied to clipboard'
|
|
323
|
+
: 'Copy code'
|
|
324
|
+
}
|
|
325
|
+
leadingIcon={
|
|
326
|
+
isCopied ? (
|
|
327
|
+
<Check size={16} aria-hidden="true" />
|
|
328
|
+
) : (
|
|
329
|
+
<Copy size={16} aria-hidden="true" />
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
/>
|
|
333
|
+
</CopyOverlay>
|
|
334
|
+
)}
|
|
289
335
|
{isDiffMode && diffLines?.length ? (
|
|
290
336
|
<CodeBlockDiffView
|
|
291
337
|
diffLines={diffLines}
|
|
@@ -130,9 +130,9 @@ export const getCodeBlockTokens = (
|
|
|
130
130
|
borderBottom: `1px solid ${foundationToken.colors.gray[200]}`,
|
|
131
131
|
padding: {
|
|
132
132
|
x: foundationToken.unit[12],
|
|
133
|
-
y: foundationToken.unit[
|
|
133
|
+
y: foundationToken.unit[8],
|
|
134
134
|
},
|
|
135
|
-
gap: foundationToken.unit[
|
|
135
|
+
gap: foundationToken.unit[6],
|
|
136
136
|
icon: {
|
|
137
137
|
width: 16,
|
|
138
138
|
},
|
|
@@ -229,11 +229,11 @@ export const getCodeBlockTokens = (
|
|
|
229
229
|
borderBottom: `1px solid ${foundationToken.colors.gray[200]}`,
|
|
230
230
|
padding: {
|
|
231
231
|
x: foundationToken.unit[16],
|
|
232
|
-
y: foundationToken.unit[
|
|
232
|
+
y: foundationToken.unit[8],
|
|
233
233
|
},
|
|
234
|
-
gap: foundationToken.unit[
|
|
234
|
+
gap: foundationToken.unit[8],
|
|
235
235
|
icon: {
|
|
236
|
-
width:
|
|
236
|
+
width: 16,
|
|
237
237
|
},
|
|
238
238
|
text: {
|
|
239
239
|
fontSize: foundationToken.font.size.body.md.fontSize,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { forwardRef, useState } from 'react'
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import Block from '../Primitives/Block/Block'
|
|
3
3
|
import { useResponsiveTokens } from '../../hooks/useResponsiveTokens'
|
|
4
4
|
import type { CodeBlockTokenType } from '../CodeBlock/codeBlock.token'
|
|
5
5
|
import { CodeEditorVariant, type CodeEditorProps } from './types'
|
|
6
|
-
import { createCopyToClipboard } from '../CodeBlock/utils'
|
|
7
6
|
import { shouldShowLineNumbers, getContainerStyles } from './utils'
|
|
8
7
|
import { CodeEditorHeader } from './CodeEditorHeader'
|
|
9
8
|
import { MonacoEditorWrapper } from './MonacoEditorWrapper'
|
|
@@ -37,6 +36,31 @@ const CodeEditor = forwardRef<HTMLDivElement, CodeEditorProps>(
|
|
|
37
36
|
) => {
|
|
38
37
|
const tokens = useResponsiveTokens<CodeBlockTokenType>('CODE_BLOCK')
|
|
39
38
|
const [isCopied, setIsCopied] = useState(false)
|
|
39
|
+
const copyFeedbackTimeoutRef = useRef<ReturnType<
|
|
40
|
+
typeof setTimeout
|
|
41
|
+
> | null>(null)
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
return () => {
|
|
45
|
+
if (copyFeedbackTimeoutRef.current !== null) {
|
|
46
|
+
clearTimeout(copyFeedbackTimeoutRef.current)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [])
|
|
50
|
+
|
|
51
|
+
const copyToClipboard = useCallback(() => {
|
|
52
|
+
navigator.clipboard.writeText(value)
|
|
53
|
+
setIsCopied(true)
|
|
54
|
+
|
|
55
|
+
if (copyFeedbackTimeoutRef.current !== null) {
|
|
56
|
+
clearTimeout(copyFeedbackTimeoutRef.current)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
copyFeedbackTimeoutRef.current = setTimeout(() => {
|
|
60
|
+
setIsCopied(false)
|
|
61
|
+
copyFeedbackTimeoutRef.current = null
|
|
62
|
+
}, 2000)
|
|
63
|
+
}, [value])
|
|
40
64
|
|
|
41
65
|
// Determine if line numbers should be shown
|
|
42
66
|
const shouldShowLineNumbersValue = shouldShowLineNumbers(
|
|
@@ -44,8 +68,6 @@ const CodeEditor = forwardRef<HTMLDivElement, CodeEditorProps>(
|
|
|
44
68
|
variant
|
|
45
69
|
)
|
|
46
70
|
|
|
47
|
-
// Handlers
|
|
48
|
-
const copyToClipboard = createCopyToClipboard(value, setIsCopied)
|
|
49
71
|
const containerStyles = getContainerStyles(minHeight, maxHeight)
|
|
50
72
|
|
|
51
73
|
return (
|
|
@@ -342,6 +342,7 @@ export const MonacoEditorWrapper = ({
|
|
|
342
342
|
const editorRef = useRef<Monaco.editor.IStandaloneCodeEditor | null>(null)
|
|
343
343
|
const monacoRef = useRef<typeof import('monaco-editor') | null>(null)
|
|
344
344
|
const shortcutDisposables = useRef<Monaco.IDisposable[]>([])
|
|
345
|
+
const focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
345
346
|
const [isEditorReady, setIsEditorReady] = useState(false)
|
|
346
347
|
const monacoLanguage = useMemo(() => mapLanguage(language), [language])
|
|
347
348
|
|
|
@@ -449,6 +450,14 @@ export const MonacoEditorWrapper = ({
|
|
|
449
450
|
}
|
|
450
451
|
}, [disposeShortcuts, isEditorReady, registerKeyboardShortcuts])
|
|
451
452
|
|
|
453
|
+
useEffect(() => {
|
|
454
|
+
return () => {
|
|
455
|
+
if (focusTimeoutRef.current !== null) {
|
|
456
|
+
clearTimeout(focusTimeoutRef.current)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}, [])
|
|
460
|
+
|
|
452
461
|
const handleEditorDidMount: OnMount = (editor, monacoInstance) => {
|
|
453
462
|
editorRef.current = editor
|
|
454
463
|
monacoRef.current = monacoInstance
|
|
@@ -502,7 +511,10 @@ export const MonacoEditorWrapper = ({
|
|
|
502
511
|
editor.onDidBlurEditorText(() => onBlur?.())
|
|
503
512
|
|
|
504
513
|
if (autoFocus && !disabled && !readOnly) {
|
|
505
|
-
|
|
514
|
+
focusTimeoutRef.current = setTimeout(
|
|
515
|
+
() => editor.focus(),
|
|
516
|
+
EDITOR_FOCUS_DELAY_MS
|
|
517
|
+
)
|
|
506
518
|
}
|
|
507
519
|
}
|
|
508
520
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
copyToClipboardWithTemporaryFeedback,
|
|
9
9
|
isDiffEditorMode,
|
|
10
10
|
shouldShowLineNumbers,
|
|
11
|
-
|
|
11
|
+
getCodeEditorV2ContainerStyles,
|
|
12
12
|
toCssValue,
|
|
13
13
|
} from './utils'
|
|
14
14
|
import { CodeEditorV2Header } from './CodeEditorV2Header'
|
|
@@ -91,7 +91,7 @@ const CodeEditorV2 = forwardRef<HTMLDivElement, CodeEditorV2Props>(
|
|
|
91
91
|
const resolvedEditorHeight = toCssValue(height)
|
|
92
92
|
const hasFixedEditorHeight = Boolean(resolvedEditorHeight)
|
|
93
93
|
const editorMinHeight = hasFixedEditorHeight ? height! : minHeight
|
|
94
|
-
const containerStyles =
|
|
94
|
+
const containerStyles = getCodeEditorV2ContainerStyles(
|
|
95
95
|
hasFixedEditorHeight ? undefined : minHeight,
|
|
96
96
|
maxHeight
|
|
97
97
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FoundationTokenType } from '../../tokens/theme.token'
|
|
2
2
|
import { ResponsiveCodeEditorV2Tokens } from './codeEditorV2.tokens'
|
|
3
|
-
import {
|
|
3
|
+
import { CodeEditorV2DiffLineType, MonacoTheme } from './codeEditorV2.types'
|
|
4
4
|
|
|
5
5
|
export const darkCodeEditorV2Tokens = (
|
|
6
6
|
foundationToken: FoundationTokenType
|
|
@@ -41,20 +41,24 @@ export const darkCodeEditorV2Tokens = (
|
|
|
41
41
|
width: '40px',
|
|
42
42
|
color: foundationToken.colors.gray[0],
|
|
43
43
|
backgroundColor: {
|
|
44
|
-
[
|
|
44
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
45
45
|
foundationToken.colors.gray[200],
|
|
46
|
-
[
|
|
47
|
-
|
|
46
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
47
|
+
foundationToken.colors.red[500],
|
|
48
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
49
|
+
foundationToken.colors.green[500],
|
|
48
50
|
},
|
|
49
51
|
borderLeft: {
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
52
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'none',
|
|
53
|
+
[CodeEditorV2DiffLineType.REMOVED]: `2px solid ${foundationToken.colors.red[600]}`,
|
|
54
|
+
[CodeEditorV2DiffLineType.ADDED]: `2px solid ${foundationToken.colors.green[600]}`,
|
|
53
55
|
},
|
|
54
56
|
borderColor: {
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
|
|
57
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
58
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
59
|
+
foundationToken.colors.red[600],
|
|
60
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
61
|
+
foundationToken.colors.green[600],
|
|
58
62
|
},
|
|
59
63
|
},
|
|
60
64
|
code: {
|
|
@@ -68,9 +72,11 @@ export const darkCodeEditorV2Tokens = (
|
|
|
68
72
|
},
|
|
69
73
|
highlightedLine: {
|
|
70
74
|
backgroundColor: {
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
|
|
75
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
76
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
77
|
+
foundationToken.colors.red[700],
|
|
78
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
79
|
+
foundationToken.colors.green[700],
|
|
74
80
|
},
|
|
75
81
|
},
|
|
76
82
|
syntax: {
|
|
@@ -120,20 +126,24 @@ export const darkCodeEditorV2Tokens = (
|
|
|
120
126
|
width: '44px',
|
|
121
127
|
color: foundationToken.colors.gray[0],
|
|
122
128
|
backgroundColor: {
|
|
123
|
-
[
|
|
129
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
124
130
|
foundationToken.colors.gray[200],
|
|
125
|
-
[
|
|
126
|
-
|
|
131
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
132
|
+
foundationToken.colors.red[500],
|
|
133
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
134
|
+
foundationToken.colors.green[500],
|
|
127
135
|
},
|
|
128
136
|
borderLeft: {
|
|
129
|
-
[
|
|
130
|
-
[
|
|
131
|
-
[
|
|
137
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'none',
|
|
138
|
+
[CodeEditorV2DiffLineType.REMOVED]: `2px solid ${foundationToken.colors.red[600]}`,
|
|
139
|
+
[CodeEditorV2DiffLineType.ADDED]: `2px solid ${foundationToken.colors.green[600]}`,
|
|
132
140
|
},
|
|
133
141
|
borderColor: {
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
|
|
142
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
143
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
144
|
+
foundationToken.colors.red[600],
|
|
145
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
146
|
+
foundationToken.colors.green[600],
|
|
137
147
|
},
|
|
138
148
|
},
|
|
139
149
|
code: {
|
|
@@ -147,9 +157,11 @@ export const darkCodeEditorV2Tokens = (
|
|
|
147
157
|
},
|
|
148
158
|
highlightedLine: {
|
|
149
159
|
backgroundColor: {
|
|
150
|
-
[
|
|
151
|
-
[
|
|
152
|
-
|
|
160
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
161
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
162
|
+
foundationToken.colors.red[700],
|
|
163
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
164
|
+
foundationToken.colors.green[700],
|
|
153
165
|
},
|
|
154
166
|
},
|
|
155
167
|
syntax: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FoundationTokenType } from '../../tokens/theme.token'
|
|
2
2
|
import { ResponsiveCodeEditorV2Tokens } from './codeEditorV2.tokens'
|
|
3
|
-
import {
|
|
3
|
+
import { CodeEditorV2DiffLineType, MonacoTheme } from './codeEditorV2.types'
|
|
4
4
|
|
|
5
5
|
export const lightCodeEditorV2Tokens = (
|
|
6
6
|
foundationToken: FoundationTokenType
|
|
@@ -41,21 +41,25 @@ export const lightCodeEditorV2Tokens = (
|
|
|
41
41
|
width: '40px',
|
|
42
42
|
color: foundationToken.colors.gray[400],
|
|
43
43
|
backgroundColor: {
|
|
44
|
-
[
|
|
44
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
45
45
|
foundationToken.colors.gray[200],
|
|
46
|
-
[
|
|
47
|
-
|
|
46
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
47
|
+
foundationToken.colors.red[200],
|
|
48
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
49
|
+
foundationToken.colors.green[200],
|
|
48
50
|
},
|
|
49
51
|
borderLeft: {
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
52
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'none',
|
|
53
|
+
[CodeEditorV2DiffLineType.REMOVED]: `2px solid ${foundationToken.colors.red[600]}`,
|
|
54
|
+
[CodeEditorV2DiffLineType.ADDED]: `2px solid ${foundationToken.colors.green[600]}`,
|
|
53
55
|
},
|
|
54
56
|
borderColor: {
|
|
55
|
-
[
|
|
57
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
56
58
|
foundationToken.colors.gray[0],
|
|
57
|
-
[
|
|
58
|
-
|
|
59
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
60
|
+
foundationToken.colors.red[600],
|
|
61
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
62
|
+
foundationToken.colors.green[600],
|
|
59
63
|
},
|
|
60
64
|
},
|
|
61
65
|
code: {
|
|
@@ -69,9 +73,11 @@ export const lightCodeEditorV2Tokens = (
|
|
|
69
73
|
},
|
|
70
74
|
highlightedLine: {
|
|
71
75
|
backgroundColor: {
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
|
|
76
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
77
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
78
|
+
foundationToken.colors.red[100],
|
|
79
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
80
|
+
foundationToken.colors.green[100],
|
|
75
81
|
},
|
|
76
82
|
},
|
|
77
83
|
syntax: {
|
|
@@ -121,21 +127,25 @@ export const lightCodeEditorV2Tokens = (
|
|
|
121
127
|
width: '44px',
|
|
122
128
|
color: foundationToken.colors.gray[400],
|
|
123
129
|
backgroundColor: {
|
|
124
|
-
[
|
|
130
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
125
131
|
foundationToken.colors.gray[200],
|
|
126
|
-
[
|
|
127
|
-
|
|
132
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
133
|
+
foundationToken.colors.red[200],
|
|
134
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
135
|
+
foundationToken.colors.green[200],
|
|
128
136
|
},
|
|
129
137
|
borderLeft: {
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
[
|
|
138
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'none',
|
|
139
|
+
[CodeEditorV2DiffLineType.REMOVED]: `2px solid ${foundationToken.colors.red[600]}`,
|
|
140
|
+
[CodeEditorV2DiffLineType.ADDED]: `2px solid ${foundationToken.colors.green[600]}`,
|
|
133
141
|
},
|
|
134
142
|
borderColor: {
|
|
135
|
-
[
|
|
143
|
+
[CodeEditorV2DiffLineType.UNCHANGED]:
|
|
136
144
|
foundationToken.colors.gray[0],
|
|
137
|
-
[
|
|
138
|
-
|
|
145
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
146
|
+
foundationToken.colors.red[600],
|
|
147
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
148
|
+
foundationToken.colors.green[600],
|
|
139
149
|
},
|
|
140
150
|
},
|
|
141
151
|
code: {
|
|
@@ -149,9 +159,11 @@ export const lightCodeEditorV2Tokens = (
|
|
|
149
159
|
},
|
|
150
160
|
highlightedLine: {
|
|
151
161
|
backgroundColor: {
|
|
152
|
-
[
|
|
153
|
-
[
|
|
154
|
-
|
|
162
|
+
[CodeEditorV2DiffLineType.UNCHANGED]: 'transparent',
|
|
163
|
+
[CodeEditorV2DiffLineType.REMOVED]:
|
|
164
|
+
foundationToken.colors.red[100],
|
|
165
|
+
[CodeEditorV2DiffLineType.ADDED]:
|
|
166
|
+
foundationToken.colors.green[100],
|
|
155
167
|
},
|
|
156
168
|
},
|
|
157
169
|
syntax: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { CSSObject } from 'styled-components'
|
|
2
|
-
import { DiffLineType } from './codeEditorV2.types'
|
|
3
2
|
import { BreakpointType } from '../../breakpoints/breakPoints'
|
|
4
3
|
import { FoundationTokenType } from '../../tokens/theme.token'
|
|
5
4
|
import { darkCodeEditorV2Tokens } from './codeEditorV2.dark.tokens'
|
|
6
5
|
import { lightCodeEditorV2Tokens } from './codeEditorV2.light.token'
|
|
7
6
|
import { Theme } from '../../context/theme.enum'
|
|
7
|
+
import { CodeEditorV2DiffLineType } from './codeEditorV2.types'
|
|
8
8
|
|
|
9
9
|
export type CodeEditorV2Tokens = {
|
|
10
10
|
backgroundColor: CSSObject['backgroundColor']
|
|
@@ -44,13 +44,13 @@ export type CodeEditorV2Tokens = {
|
|
|
44
44
|
width: CSSObject['width']
|
|
45
45
|
color: CSSObject['color']
|
|
46
46
|
backgroundColor: {
|
|
47
|
-
[key in
|
|
47
|
+
[key in CodeEditorV2DiffLineType]: CSSObject['backgroundColor']
|
|
48
48
|
}
|
|
49
49
|
borderLeft: {
|
|
50
|
-
[key in
|
|
50
|
+
[key in CodeEditorV2DiffLineType]: CSSObject['borderLeft']
|
|
51
51
|
}
|
|
52
52
|
borderColor: {
|
|
53
|
-
[key in
|
|
53
|
+
[key in CodeEditorV2DiffLineType]: CSSObject['color']
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
// Code tokens
|
|
@@ -66,7 +66,7 @@ export type CodeEditorV2Tokens = {
|
|
|
66
66
|
// Highlighted line tokens (for diff mode and code highlighting)
|
|
67
67
|
highlightedLine: {
|
|
68
68
|
backgroundColor: {
|
|
69
|
-
[key in
|
|
69
|
+
[key in CodeEditorV2DiffLineType]: CSSObject['backgroundColor']
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
// Syntax highlighting tokens
|
|
@@ -11,18 +11,18 @@ export enum MonacoTheme {
|
|
|
11
11
|
LIGHT = 'light',
|
|
12
12
|
DARK = 'dark',
|
|
13
13
|
}
|
|
14
|
-
export enum
|
|
14
|
+
export enum CodeEditorV2DiffLineType {
|
|
15
15
|
ADDED = 'added',
|
|
16
16
|
REMOVED = 'removed',
|
|
17
17
|
UNCHANGED = 'unchanged',
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type CodeEditorV2DiffLine = {
|
|
21
21
|
content: string
|
|
22
|
-
type:
|
|
22
|
+
type: CodeEditorV2DiffLineType
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type
|
|
25
|
+
export type CodeEditorV2SupportedLanguage =
|
|
26
26
|
| 'javascript'
|
|
27
27
|
| 'typescript'
|
|
28
28
|
| 'jsx'
|
|
@@ -57,7 +57,7 @@ export type CodeEditorV2Props = {
|
|
|
57
57
|
rightSlot?: ReactNode
|
|
58
58
|
showCopyButton?: boolean
|
|
59
59
|
}
|
|
60
|
-
language?:
|
|
60
|
+
language?: CodeEditorV2SupportedLanguage
|
|
61
61
|
placeholder?: string
|
|
62
62
|
readOnly?: boolean
|
|
63
63
|
disabled?: boolean
|
|
@@ -98,7 +98,7 @@ export const isDiffEditorMode = (
|
|
|
98
98
|
/**
|
|
99
99
|
* Calculates container styles with min/max height
|
|
100
100
|
*/
|
|
101
|
-
export const
|
|
101
|
+
export const getCodeEditorV2ContainerStyles = (
|
|
102
102
|
minHeight?: string | number,
|
|
103
103
|
maxHeight?: string | number
|
|
104
104
|
): React.CSSProperties => {
|