@coveord/plasma-mantine 54.4.0 → 55.0.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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-test.log +35 -35
- package/__mocks__/@monaco-editor/react.tsx +5 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/button/ButtonWithDisabledTooltip.d.ts +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.js +25 -2
- package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.module.css +10 -0
- package/dist/cjs/components/collection/Collection.d.ts +6 -0
- package/dist/cjs/components/collection/Collection.d.ts.map +1 -1
- package/dist/cjs/components/collection/Collection.js +7 -4
- package/dist/cjs/components/collection/Collection.js.map +1 -1
- package/dist/cjs/components/copyToClipboard/CopyToClipboard.d.ts +9 -1
- package/dist/cjs/components/copyToClipboard/CopyToClipboard.d.ts.map +1 -1
- package/dist/cjs/components/copyToClipboard/CopyToClipboard.js +5 -6
- package/dist/cjs/components/copyToClipboard/CopyToClipboard.js.map +1 -1
- package/dist/cjs/components/index.d.ts +7 -6
- package/dist/cjs/components/index.d.ts.map +1 -1
- package/dist/cjs/components/index.js +7 -6
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/components/read-only/PasswordInput.d.ts +8 -0
- package/dist/cjs/components/read-only/PasswordInput.d.ts.map +1 -0
- package/dist/cjs/components/read-only/PasswordInput.js +29 -0
- package/dist/cjs/components/read-only/PasswordInput.js.map +1 -0
- package/dist/cjs/components/read-only/ReadOnlyInputStyles.d.ts +13 -0
- package/dist/cjs/components/read-only/ReadOnlyInputStyles.d.ts.map +1 -0
- package/dist/cjs/components/read-only/ReadOnlyInputStyles.js +25 -0
- package/dist/cjs/components/read-only/ReadOnlyInputStyles.js.map +1 -0
- package/dist/cjs/components/read-only/Select.d.ts +7 -0
- package/dist/cjs/components/read-only/Select.d.ts.map +1 -0
- package/dist/cjs/components/read-only/Select.js +29 -0
- package/dist/cjs/components/read-only/Select.js.map +1 -0
- package/dist/cjs/components/read-only/index.d.ts +3 -0
- package/dist/cjs/components/read-only/index.d.ts.map +1 -0
- package/dist/cjs/components/read-only/index.js +9 -0
- package/dist/cjs/components/read-only/index.js.map +1 -0
- package/dist/cjs/components/table/index.d.ts +1 -1
- package/dist/cjs/components/table/index.d.ts.map +1 -1
- package/dist/cjs/components/table/index.js +0 -4
- package/dist/cjs/components/table/index.js.map +1 -1
- package/dist/cjs/components/table/table-predicate/TablePredicate.d.ts +2 -3
- package/dist/cjs/components/table/table-predicate/TablePredicate.d.ts.map +1 -1
- package/dist/cjs/components/table/table-predicate/TablePredicate.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/styles/Input.module.css +1 -1
- package/dist/cjs/styles/ReadOnlyInput.module.css +8 -0
- package/dist/cjs/styles/ReadOnlyState.module.css +3 -0
- package/dist/cjs/theme/Theme.d.ts.map +1 -1
- package/dist/cjs/theme/Theme.js +94 -6
- package/dist/cjs/theme/Theme.js.map +1 -1
- package/dist/esm/components/button/ButtonWithDisabledTooltip.d.ts +1 -1
- package/dist/esm/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.js +26 -1
- package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.module.css +10 -0
- package/dist/esm/components/collection/Collection.d.ts +6 -0
- package/dist/esm/components/collection/Collection.d.ts.map +1 -1
- package/dist/esm/components/collection/Collection.js +6 -4
- package/dist/esm/components/collection/Collection.js.map +1 -1
- package/dist/esm/components/copyToClipboard/CopyToClipboard.d.ts +9 -1
- package/dist/esm/components/copyToClipboard/CopyToClipboard.d.ts.map +1 -1
- package/dist/esm/components/copyToClipboard/CopyToClipboard.js +3 -5
- package/dist/esm/components/copyToClipboard/CopyToClipboard.js.map +1 -1
- package/dist/esm/components/index.d.ts +7 -6
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +7 -6
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/read-only/PasswordInput.d.ts +8 -0
- package/dist/esm/components/read-only/PasswordInput.d.ts.map +1 -0
- package/dist/esm/components/read-only/PasswordInput.js +20 -0
- package/dist/esm/components/read-only/PasswordInput.js.map +1 -0
- package/dist/esm/components/read-only/ReadOnlyInputStyles.d.ts +13 -0
- package/dist/esm/components/read-only/ReadOnlyInputStyles.d.ts.map +1 -0
- package/dist/esm/components/read-only/ReadOnlyInputStyles.js +13 -0
- package/dist/esm/components/read-only/ReadOnlyInputStyles.js.map +1 -0
- package/dist/esm/components/read-only/Select.d.ts +7 -0
- package/dist/esm/components/read-only/Select.d.ts.map +1 -0
- package/dist/esm/components/read-only/Select.js +20 -0
- package/dist/esm/components/read-only/Select.js.map +1 -0
- package/dist/esm/components/read-only/index.d.ts +3 -0
- package/dist/esm/components/read-only/index.d.ts.map +1 -0
- package/dist/esm/components/read-only/index.js +4 -0
- package/dist/esm/components/read-only/index.js.map +1 -0
- package/dist/esm/components/table/index.d.ts +1 -1
- package/dist/esm/components/table/index.d.ts.map +1 -1
- package/dist/esm/components/table/index.js +0 -1
- package/dist/esm/components/table/index.js.map +1 -1
- package/dist/esm/components/table/table-predicate/TablePredicate.d.ts +2 -3
- package/dist/esm/components/table/table-predicate/TablePredicate.d.ts.map +1 -1
- package/dist/esm/components/table/table-predicate/TablePredicate.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/styles/Input.module.css +1 -1
- package/dist/esm/styles/ReadOnlyInput.module.css +8 -0
- package/dist/esm/styles/ReadOnlyState.module.css +3 -0
- package/dist/esm/theme/Theme.d.ts.map +1 -1
- package/dist/esm/theme/Theme.js +95 -7
- package/dist/esm/theme/Theme.js.map +1 -1
- package/package.json +9 -9
- package/src/components/code-editor/CodeEditor.module.css +10 -0
- package/src/components/code-editor/CodeEditor.tsx +26 -1
- package/src/components/collection/Collection.tsx +12 -3
- package/src/components/copyToClipboard/CopyToClipboard.tsx +12 -6
- package/src/components/index.ts +7 -6
- package/src/components/read-only/PasswordInput.tsx +11 -0
- package/src/components/read-only/ReadOnlyInputStyles.ts +13 -0
- package/src/components/read-only/Select.tsx +11 -0
- package/src/components/read-only/index.ts +2 -0
- package/src/components/table/__tests__/TablePredicate.spec.tsx +2 -1
- package/src/components/table/index.ts +1 -1
- package/src/components/table/table-predicate/TablePredicate.tsx +2 -3
- package/src/index.ts +2 -0
- package/src/styles/Input.module.css +1 -1
- package/src/styles/ReadOnlyInput.module.css +8 -0
- package/src/styles/ReadOnlyState.module.css +3 -0
- package/src/theme/Theme.tsx +86 -3
|
@@ -21,7 +21,7 @@ export interface ButtonWithDisabledTooltipProps {
|
|
|
21
21
|
}
|
|
22
22
|
export declare const ButtonWithDisabledTooltip: (<C = "div">(props: import("@mantine/utils").PolymorphicComponentProps<C, ButtonWithDisabledTooltipProps>) => React.ReactElement) & Omit<import("react").FunctionComponent<(ButtonWithDisabledTooltipProps & {
|
|
23
23
|
component?: any;
|
|
24
|
-
} & Omit<Pick<any, string | number | symbol>, "component"
|
|
24
|
+
} & Omit<Pick<any, string | number | symbol>, keyof ButtonWithDisabledTooltipProps | "component"> & {
|
|
25
25
|
ref?: any;
|
|
26
26
|
}) | (ButtonWithDisabledTooltipProps & {
|
|
27
27
|
component: React.ElementType<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKH,iBAAiB,EAIjB,UAAU,EAKb,MAAM,e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B,gBAAgB,GAAG,mBAAmB,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CACzF,EACD,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;IACrF,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,IAAI,IAAI,CAAC;IAChB,qDAAqD;IACrD,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAClC;AASD,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CAkLzD,CAAC"}
|
|
@@ -97,6 +97,24 @@ var CodeEditor = function(props) {
|
|
|
97
97
|
_xml.XML.register(monaco);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
+
var registerThemes = function(monaco) {
|
|
101
|
+
monaco.editor.defineTheme('light-disabled', {
|
|
102
|
+
base: 'vs',
|
|
103
|
+
inherit: true,
|
|
104
|
+
rules: [],
|
|
105
|
+
colors: {
|
|
106
|
+
'editor.background': theme.colors.gray[2]
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
monaco.editor.defineTheme('vs-dark-disabled', {
|
|
110
|
+
base: 'vs-dark',
|
|
111
|
+
inherit: true,
|
|
112
|
+
rules: [],
|
|
113
|
+
colors: {
|
|
114
|
+
'editor.background': theme.colors.navy[7]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
};
|
|
100
118
|
var handleSearch = function() {
|
|
101
119
|
if (editorRef.current) {
|
|
102
120
|
editorRef.current.focus();
|
|
@@ -156,15 +174,19 @@ var CodeEditor = function(props) {
|
|
|
156
174
|
})
|
|
157
175
|
]
|
|
158
176
|
});
|
|
177
|
+
var editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';
|
|
178
|
+
if (disabled) {
|
|
179
|
+
editorTheme += '-disabled';
|
|
180
|
+
}
|
|
159
181
|
var _editor = loaded ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.Box, {
|
|
160
182
|
p: "md",
|
|
161
183
|
pl: "xs",
|
|
162
|
-
className: (0, _clsx.default)(_CodeEditormodulecss.default.editor, _define_property._({}, _CodeEditormodulecss.default.valid, !renderErrorOutline), _define_property._({}, _CodeEditormodulecss.default.error, renderErrorOutline)),
|
|
184
|
+
className: (0, _clsx.default)(_CodeEditormodulecss.default.editor, _define_property._({}, _CodeEditormodulecss.default.valid, !renderErrorOutline), _define_property._({}, _CodeEditormodulecss.default.error, renderErrorOutline), _define_property._({}, _CodeEditormodulecss.default.disabled, disabled)),
|
|
163
185
|
"data-testid": "editor-wrapper",
|
|
164
186
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_react.default, {
|
|
165
187
|
onValidate: handleValidate,
|
|
166
188
|
defaultLanguage: language,
|
|
167
|
-
theme:
|
|
189
|
+
theme: editorTheme,
|
|
168
190
|
options: {
|
|
169
191
|
minimap: {
|
|
170
192
|
enabled: false
|
|
@@ -181,6 +203,7 @@ var CodeEditor = function(props) {
|
|
|
181
203
|
onMount: function(editor, monaco) {
|
|
182
204
|
editorRef.current = editor;
|
|
183
205
|
registerLanguages(monaco);
|
|
206
|
+
registerThemes(monaco);
|
|
184
207
|
editor.onDidFocusEditorText(function() {
|
|
185
208
|
return onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
186
209
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={colorScheme === 'light' ? 'light' : 'vs-dark'}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","theme","useMantineTheme","colorScheme","useMantineColorScheme","useEffect","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Input","Label","_description","Description","_error","mt","Space","h","_header","Box","_buttons","Group","justify","gap","Search","CopyToClipboard","_editor","p","pl","className","cx","CodeEditorClasses","editor","valid","data-testid","Editor","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","Math","max","mah"],"mappings":";;;;+BAmFaA;;;eAAAA;;;;;;;;;;;;;oBArEN;qBACuB;+DACO;sBAEwB;6DAE9C;sBACe;+BACA;4EACA;mBACZ;sBACG;AAmDrB,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEO,IAAML,aAAiD,SAACM;IAC3D,IAoBIC,YAAAA,IAAAA,cAAQ,EAAC,cAAcN,cAAcK,QAnBrCJ,WAmBAK,UAnBAL,UACAE,eAkBAG,UAlBAH,cACAI,WAiBAD,UAjBAC,UACAC,SAgBAF,UAhBAE,QACAC,WAeAH,UAfAG,UACAC,UAcAJ,UAdAI,SACAC,QAaAL,UAbAK,OACAC,QAYAN,UAZAM,OACAC,WAWAP,UAXAO,UACAC,aAUAR,UAVAQ,YACAC,QASAT,UATAS,OACAC,aAQAV,UARAU,YACAC,cAOAX,UAPAW,aACAC,mBAMAZ,UANAY,kBACAd,YAKAE,UALAF,WACAe,YAIAb,UAJAa,WACAC,WAGAd,UAHAc,UACAlB,eAEAI,UAFAJ,cACGmB,sCACHf;QAnBAL;QACAE;QACAI;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAd;QACAe;QACAC;QACAlB;;IAGJ,IAA4BoB,+BAAAA,IAAAA,gBAAQ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A;;gBAClC2E,OAAOoB,mBAAmB,qCAAC;;;;gCACvB;;oCAAMpB,OAAOqB,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAAC1B,WAAWE,4BAAiB,CAACC,MAAM;kBACvC,cAAA,qBAACwB,YAAM;;IAIf,qBACI,sBAACC,WAAK;QAACnC,SAAQ;QAAaC,KAAK;QAAGN,GAAGyC,KAAKC,GAAG,CAAClF,cAAc1B;QAAY6G,KAAK9F;QAAWY,KAAKA;OAASV;;YACnGkD;YACAE;YACAM;YACAZ;;;AAGb"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const registerThemes = (monaco: Monaco) => {\n monaco.editor.defineTheme('light-disabled', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.gray[2],\n },\n });\n monaco.editor.defineTheme('vs-dark-disabled', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.navy[7],\n },\n });\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n let editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';\n if (disabled) {\n editorTheme += '-disabled';\n }\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n {[CodeEditorClasses.disabled]: disabled},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={editorTheme}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n registerThemes(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","registerThemes","editor","defineTheme","base","inherit","rules","colors","theme","gray","navy","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","useMantineTheme","colorScheme","useMantineColorScheme","useEffect","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Input","Label","_description","Description","_error","mt","Space","h","_header","Box","_buttons","Group","justify","gap","Search","CopyToClipboard","editorTheme","_editor","p","pl","className","cx","CodeEditorClasses","valid","data-testid","Editor","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","Math","max","mah"],"mappings":";;;;+BAmFaA;;;eAAAA;;;;;;;;;;;;;oBArEN;qBACuB;+DACO;sBAEwB;6DAE9C;sBACe;+BACA;4EACA;mBACZ;sBACG;AAmDrB,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;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,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAACzB,WAAWE,4BAAiB,CAACnD,MAAM;kBACvC,cAAA,qBAAC2E,YAAM;;IAIf,qBACI,sBAACC,WAAK;QAACnC,SAAQ;QAAaC,KAAK;QAAGN,GAAGyC,KAAKC,GAAG,CAAC3F,cAAc1B;QAAYsH,KAAKvG;QAAWY,KAAKA;OAASV;;YACnG2D;YACAE;YACAO;YACAb;;;AAGb"}
|
|
@@ -71,6 +71,12 @@ export interface CollectionProps<T> extends __InputWrapperProps, BoxProps, Style
|
|
|
71
71
|
* @default false
|
|
72
72
|
*/
|
|
73
73
|
disabled?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the collection is readOnly. If true, the collection will not allow adding or removing items
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
readOnly?: boolean;
|
|
74
80
|
/**
|
|
75
81
|
* Function that determines if the add item button should be enabled given the current items of the collection.
|
|
76
82
|
* The button is always enabled if this props remains undefined
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../../src/components/collection/Collection.tsx"],"names":[],"mappings":"AAIA,OAAO,EAEH,QAAQ,EACR,OAAO,EAGP,cAAc,EAEd,cAAc,EAEd,mBAAmB,EAGtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAC,0BAA0B,EAAW,MAAM,aAAa,CAAC;AAMjE,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,mBAAmB,EAAE,QAAQ,EAAE,cAAc,CAAC,iBAAiB,CAAC;IACxG;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC;IACX;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE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ACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,OAAO,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,cAAc,GAAG,YAAY,CAAC;AAEpF,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC;IACpC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,WAAW,EAAE,qBAAqB,CAAC;CACtC,CAAC,CAAC;AAaH,eAAO,MAAM,UAAU;KAAI,CAAC,SAAU,eAAe,CAAC,CAAC,CAAC,GAAG;QAAC,GAAG,CAAC,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;KAAC;;eAhBpF,eAAe,CAAC,OAAO,CAAC;aAC1B,cAAc;qBACN,qBAAqB;;CAkKrC,CAAC"}
|
|
@@ -29,6 +29,7 @@ var defaultProps = {
|
|
|
29
29
|
addLabel: 'Add item',
|
|
30
30
|
addDisabledTooltip: 'There is already an empty item',
|
|
31
31
|
disabled: false,
|
|
32
|
+
readOnly: false,
|
|
32
33
|
gap: 'xs',
|
|
33
34
|
required: false,
|
|
34
35
|
getItemId: function(param) {
|
|
@@ -37,7 +38,7 @@ var defaultProps = {
|
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
var Collection = function(props) {
|
|
40
|
-
var _useProps = (0, _core1.useProps)('Collection', defaultProps, props), value = _useProps.value, onChange = _useProps.onChange, onRemoveItem = _useProps.onRemoveItem, onReorderItem = _useProps.onReorderItem, onInsertItem = _useProps.onInsertItem, disabled = _useProps.disabled, draggable = _useProps.draggable, children = _useProps.children, gap = _useProps.gap, required = _useProps.required, newItem = _useProps.newItem, addLabel = _useProps.addLabel, addDisabledTooltip = _useProps.addDisabledTooltip, allowAdd = _useProps.allowAdd, label = _useProps.label, labelProps = _useProps.labelProps, withAsterisk = _useProps.withAsterisk, description = _useProps.description, descriptionProps = _useProps.descriptionProps, error = _useProps.error, errorProps = _useProps.errorProps, getItemId = _useProps.getItemId, ref = _useProps.ref, // Style props
|
|
41
|
+
var _useProps = (0, _core1.useProps)('Collection', defaultProps, props), value = _useProps.value, onChange = _useProps.onChange, onRemoveItem = _useProps.onRemoveItem, onReorderItem = _useProps.onReorderItem, onInsertItem = _useProps.onInsertItem, disabled = _useProps.disabled, readOnly = _useProps.readOnly, draggable = _useProps.draggable, children = _useProps.children, gap = _useProps.gap, required = _useProps.required, newItem = _useProps.newItem, addLabel = _useProps.addLabel, addDisabledTooltip = _useProps.addDisabledTooltip, allowAdd = _useProps.allowAdd, label = _useProps.label, labelProps = _useProps.labelProps, withAsterisk = _useProps.withAsterisk, description = _useProps.description, descriptionProps = _useProps.descriptionProps, error = _useProps.error, errorProps = _useProps.errorProps, getItemId = _useProps.getItemId, ref = _useProps.ref, // Style props
|
|
41
42
|
style = _useProps.style, className = _useProps.className, classNames = _useProps.classNames, styles = _useProps.styles, unstyled = _useProps.unstyled, others = _object_without_properties._(_useProps, [
|
|
42
43
|
"value",
|
|
43
44
|
"onChange",
|
|
@@ -45,6 +46,7 @@ var Collection = function(props) {
|
|
|
45
46
|
"onReorderItem",
|
|
46
47
|
"onInsertItem",
|
|
47
48
|
"disabled",
|
|
49
|
+
"readOnly",
|
|
48
50
|
"draggable",
|
|
49
51
|
"children",
|
|
50
52
|
"gap",
|
|
@@ -81,6 +83,7 @@ var Collection = function(props) {
|
|
|
81
83
|
var sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.PointerSensor), (0, _core.useSensor)(_core.KeyboardSensor, {
|
|
82
84
|
coordinateGetter: _sortable.sortableKeyboardCoordinates
|
|
83
85
|
}));
|
|
86
|
+
var canEdit = !disabled && !readOnly;
|
|
84
87
|
var hasOnlyOneItem = value.length === 1;
|
|
85
88
|
/**
|
|
86
89
|
* Enforcing onChange when the value is modified will make sure the errors are carried through.
|
|
@@ -117,7 +120,7 @@ var Collection = function(props) {
|
|
|
117
120
|
var items = standardizedItems.map(function(item, index) {
|
|
118
121
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_CollectionItem.CollectionItem, {
|
|
119
122
|
id: item.id,
|
|
120
|
-
disabled:
|
|
123
|
+
disabled: !canEdit,
|
|
121
124
|
draggable: draggable,
|
|
122
125
|
onRemove: function() {
|
|
123
126
|
return onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
|
|
@@ -128,7 +131,7 @@ var Collection = function(props) {
|
|
|
128
131
|
});
|
|
129
132
|
var _allowAdd;
|
|
130
133
|
var addAllowed = (_allowAdd = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(value)) !== null && _allowAdd !== void 0 ? _allowAdd : true;
|
|
131
|
-
var _addButton =
|
|
134
|
+
var _addButton = canEdit ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core1.Group, {
|
|
132
135
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_core1.Tooltip, {
|
|
133
136
|
label: addDisabledTooltip,
|
|
134
137
|
disabled: addAllowed,
|
|
@@ -147,7 +150,7 @@ var Collection = function(props) {
|
|
|
147
150
|
})
|
|
148
151
|
})
|
|
149
152
|
})
|
|
150
|
-
});
|
|
153
|
+
}) : null;
|
|
151
154
|
var getIndex = function(id) {
|
|
152
155
|
return standardizedItems.findIndex(function(item) {
|
|
153
156
|
return item.id === id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n Box,\n BoxProps,\n Factory,\n Group,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n Tooltip,\n __InputWrapperProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n */\n getItemId?: (originalItem: T) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: ReorderPayload) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n gap: 'xs',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <>\n {_label}\n {_description}\n </>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={disabled}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftSection={<AddSize16Px height={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","gap","required","getItemId","id","props","useProps","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","useStyles","name","classes","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","coordinateGetter","sortableKeyboardCoordinates","hasOnlyOneItem","length","useDidUpdate","JSON","stringify","isRequired","_label","Input","Label","_description","Description","_error","Error","_header","standardizedItems","map","item","index","String","data","items","CollectionItem","onRemove","removable","addAllowed","_addButton","Group","Tooltip","Box","Button","variant","leftSection","AddSize16Px","height","onClick","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","CollectionProvider","DndContext","onDragEnd","modifiers","restrictToVerticalAxis","restrictToParentElement","SortableContext","strategy","verticalListSortingStrategy","Stack","extend","identity"],"mappings":";;;;+BAoJaA;;;eAAAA;;;;;;;;gCApJa;oBACmE;yBAC/B;wBAC0B;qBAcjF;qBAEoB;qBAGwB;sBAC9B;4EACD;iCACa;8BACJ;AAgH7B,IAAMC,eAAkD;IACpDC,WAAW;IACXC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,KAAK;IACLC,UAAU;IACVC,WAAW;YAAEC,WAAAA;eAAaA;;AAC9B;AAEO,IAAMT,aAAa,SAAKU;IAC3B,IAgCIC,YAAAA,IAAAA,eAAQ,EAAC,cAAcV,c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;;oBAClCC,SAAS;4BAA4BnE;+BAAtBI,aAAaE,SAASN,CAAAA,gBAAAA,kBAAAA,4BAAAA,MAAOkC,MAAM,cAAblC,2BAAAA,gBAAiB;;oBACtDP,UAAU,CAACgE;8BAEVlE;;;;;IAOrB,IAAM6E,WAAW,SAACvE;eAAekD,kBAAkBsB,SAAS,CAAC,SAACpB;mBAASA,KAAKpD,EAAE,KAAKA;;;IAEnF,IAAMyE,gBAAgB;YAAEC,aAAAA,MAAMC,eAAAA;QAC1B,IAAID,MAAM;YACN,IAAME,cAAcL,SAASjB,OAAOqB,OAAO3E,EAAE;YAC7C,IAAM6E,YAAYN,SAASjB,OAAOoB,KAAK1E,EAAE;YACzC,IAAI4E,gBAAgBC,WAAW;gBAC3BvE,0BAAAA,oCAAAA,cAAgB;oBAACwE,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,qBAACG,qCAAkB;QAAC7E,OAAO;YAACsB,WAAAA;QAAS;kBACjC,cAAA,qBAACwD,gBAAU;YACPC,WAAWT;YACX5C,SAASA;YACTsD,WAAW;gBAACC,iCAAsB;gBAAEC,kCAAuB;aAAC;sBAE5D,cAAA,qBAACC,yBAAe;gBAAC9B,OAAON;gBAAmBqC,UAAUC,qCAA2B;0BAC5E,cAAA,sBAACxB,UAAG;oBAAC9C,KAAKA;mBAASM,QAAYC,UAAU;;wBACpCwB;sCACD,sBAACwC,YAAK;4BAAC5F,KAAKA;;gCACP2D;gCACAK;gCACAd;;;;;;;;AAO7B;AAEAxD,WAAWmG,MAAM,GAAGC,eAAQ"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {DndContext, DragEndEvent, KeyboardSensor, PointerSensor, useSensor, useSensors} from '@dnd-kit/core';\nimport {restrictToParentElement, restrictToVerticalAxis} from '@dnd-kit/modifiers';\nimport {SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy} from '@dnd-kit/sortable';\nimport {\n Box,\n BoxProps,\n Factory,\n Group,\n Input,\n MantineSpacing,\n Stack,\n StylesApiProps,\n Tooltip,\n __InputWrapperProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport {ReorderPayload} from '@mantine/form/lib/types';\nimport {useDidUpdate} from '@mantine/hooks';\nimport {ForwardedRef, ReactNode} from 'react';\n\nimport {CustomComponentThemeExtend, identity} from '../../utils';\nimport {Button} from '../button';\nimport classes from './Collection.module.css';\nimport {CollectionProvider} from './CollectionContext';\nimport {CollectionItem} from './CollectionItem';\n\nexport interface CollectionProps<T> extends __InputWrapperProps, BoxProps, StylesApiProps<CollectionFactory> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * Defines how each item is uniquely identified. It is highly recommended that you specify this prop to an ID that makes sense.\n *\n * This method is required when using this component with ReactHookForm.\n *\n * @see {@link https://react-hook-form.com/api/usefieldarray/} for using a collection with ReactHookForm.\n *\n * @param originalItem The original item\n */\n getItemId?: (originalItem: T) => string;\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Function that gets called whenever a collection item needs to be reordered\n *\n * @param payload The origin and destination index of the item to reorder\n */\n onReorderItem?: (payload: ReorderPayload) => void;\n /**\n * Function that gets called when a new item needs to be added to the collection\n *\n * @param value The value of the item to insert\n * @param index The index of the new item to insert\n */\n onInsertItem?: (value: T, index: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Whether the collection is readOnly. If true, the collection will not allow adding or removing items\n *\n * @default false\n */\n readOnly?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The gap between the colleciton items\n *\n * @default 'xs'\n */\n gap?: MantineSpacing;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nexport type CollectionStylesNames = 'root' | 'item' | 'itemDragging' | 'dragHandle';\n\nexport type CollectionFactory = Factory<{\n props: CollectionProps<unknown>;\n ref: HTMLDivElement;\n stylesNames: CollectionStylesNames;\n}>;\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n readOnly: false,\n gap: 'xs',\n required: false,\n getItemId: ({id}: any) => id,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T> & {ref?: ForwardedRef<HTMLDivElement>}) => {\n const {\n value,\n onChange,\n onRemoveItem,\n onReorderItem,\n onInsertItem,\n disabled,\n readOnly,\n draggable,\n children,\n gap,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n withAsterisk,\n description,\n descriptionProps,\n error,\n errorProps,\n getItemId,\n ref,\n\n // Style props\n style,\n className,\n classNames,\n styles,\n unstyled,\n ...others\n } = useProps('Collection', defaultProps as CollectionProps<T>, props);\n\n const getStyles = useStyles<CollectionFactory>({\n name: 'Collection',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n });\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates,\n }),\n );\n\n const canEdit = !disabled && !readOnly;\n const hasOnlyOneItem = value.length === 1;\n\n /**\n * Enforcing onChange when the value is modified will make sure the errors are carried through.\n */\n useDidUpdate(() => {\n onChange?.(value);\n }, [JSON.stringify(value)]);\n\n const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;\n const _label = label ? (\n <Input.Label required={isRequired} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <>\n {_label}\n {_description}\n </>\n ) : null;\n\n const standardizedItems = value.map((item, index) => ({id: getItemId?.(item) ?? String(index), data: item}));\n\n const items = standardizedItems.map((item, index) => (\n <CollectionItem\n key={item.id}\n id={item.id}\n disabled={!canEdit}\n draggable={draggable}\n onRemove={() => onRemoveItem?.(index)}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item.data, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(value) ?? true;\n\n const _addButton = canEdit ? (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftSection={<AddSize16Px height={16} />}\n onClick={() => onInsertItem(newItem, value?.length ?? 0)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n ) : null;\n\n const getIndex = (id: string) => standardizedItems.findIndex((item) => item.id === id);\n\n const handleDragEnd = ({over, active}: DragEndEvent): void => {\n if (over) {\n const activeIndex = getIndex(String(active.id));\n const overIndex = getIndex(String(over.id));\n if (activeIndex !== overIndex) {\n onReorderItem?.({from: activeIndex, to: overIndex});\n }\n }\n };\n\n return (\n <CollectionProvider value={{getStyles}}>\n <DndContext\n onDragEnd={handleDragEnd}\n sensors={sensors}\n modifiers={[restrictToVerticalAxis, restrictToParentElement]}\n >\n <SortableContext items={standardizedItems} strategy={verticalListSortingStrategy}>\n <Box ref={ref} {...others} {...getStyles('root')}>\n {_header}\n <Stack gap={gap}>\n {items}\n {_addButton}\n {_error}\n </Stack>\n </Box>\n </SortableContext>\n </DndContext>\n </CollectionProvider>\n );\n};\n\nCollection.extend = identity as CustomComponentThemeExtend<CollectionFactory>;\n"],"names":["Collection","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","readOnly","gap","required","getItemId","id","props","useProps","value","onChange","onRemoveItem","onReorderItem","onInsertItem","children","newItem","allowAdd","label","labelProps","withAsterisk","description","descriptionProps","error","errorProps","ref","style","className","classNames","styles","unstyled","others","getStyles","useStyles","name","classes","sensors","useSensors","useSensor","PointerSensor","KeyboardSensor","coordinateGetter","sortableKeyboardCoordinates","canEdit","hasOnlyOneItem","length","useDidUpdate","JSON","stringify","isRequired","_label","Input","Label","_description","Description","_error","Error","_header","standardizedItems","map","item","index","String","data","items","CollectionItem","onRemove","removable","addAllowed","_addButton","Group","Tooltip","Box","Button","variant","leftSection","AddSize16Px","height","onClick","getIndex","findIndex","handleDragEnd","over","active","activeIndex","overIndex","from","to","CollectionProvider","DndContext","onDragEnd","modifiers","restrictToVerticalAxis","restrictToParentElement","SortableContext","strategy","verticalListSortingStrategy","Stack","extend","identity"],"mappings":";;;;+BA2JaA;;;eAAAA;;;;;;;;gCA3Ja;oBACmE;yBAC/B;wBAC0B;qBAcjF;qBAEoB;qBAGwB;sBAC9B;4EACD;iCACa;8BACJ;AAsH7B,IAAMC,eAAkD;IACpDC,WAAW;IACXC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,UAAU;IACVC,KAAK;IACLC,UAAU;IACVC,WAAW;YAAEC,WAAAA;eAAaA;;AAC9B;AAEO,IAAMV,aAAa,SAAKW;IAC3B,IAiCIC,YAAAA,IAAAA,eAAQ,EAAC,cAAcX,cAAoCU,QAhC3DE,QAgCAD,UAhCAC,OACAC,WA+BAF,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Aa,qBAACC,6BAAW;wBAACC,QAAQ;;oBAClCC,SAAS;4BAA4BpE;+BAAtBI,aAAaE,SAASN,CAAAA,gBAAAA,kBAAAA,4BAAAA,MAAOmC,MAAM,cAAbnC,2BAAAA,gBAAiB;;oBACtDR,UAAU,CAACkE;8BAEVpE;;;;SAKjB;IAEJ,IAAM+E,WAAW,SAACxE;eAAemD,kBAAkBsB,SAAS,CAAC,SAACpB;mBAASA,KAAKrD,EAAE,KAAKA;;;IAEnF,IAAM0E,gBAAgB;YAAEC,aAAAA,MAAMC,eAAAA;QAC1B,IAAID,MAAM;YACN,IAAME,cAAcL,SAASjB,OAAOqB,OAAO5E,EAAE;YAC7C,IAAM8E,YAAYN,SAASjB,OAAOoB,KAAK3E,EAAE;YACzC,IAAI6E,gBAAgBC,WAAW;gBAC3BxE,0BAAAA,oCAAAA,cAAgB;oBAACyE,MAAMF;oBAAaG,IAAIF;gBAAS;YACrD;QACJ;IACJ;IAEA,qBACI,qBAACG,qCAAkB;QAAC9E,OAAO;YAACsB,WAAAA;QAAS;kBACjC,cAAA,qBAACyD,gBAAU;YACPC,WAAWT;YACX7C,SAASA;YACTuD,WAAW;gBAACC,iCAAsB;gBAAEC,kCAAuB;aAAC;sBAE5D,cAAA,qBAACC,yBAAe;gBAAC9B,OAAON;gBAAmBqC,UAAUC,qCAA2B;0BAC5E,cAAA,sBAACxB,UAAG;oBAAC/C,KAAKA;mBAASM,QAAYC,UAAU;;wBACpCyB;sCACD,sBAACwC,YAAK;4BAAC7F,KAAKA;;gCACP4D;gCACAK;gCACAd;;;;;;;;AAO7B;AAEA1D,WAAWqG,MAAM,GAAGC,eAAQ"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MantineColor } from '@mantine/core';
|
|
2
|
+
import { FunctionComponent } from 'react';
|
|
1
3
|
export interface CopyToClipboardProps {
|
|
2
4
|
/**
|
|
3
5
|
* The value to be copied to the clipboard.
|
|
@@ -13,6 +15,12 @@ export interface CopyToClipboardProps {
|
|
|
13
15
|
* Called each time the value is copied to the clipboard
|
|
14
16
|
*/
|
|
15
17
|
onCopy?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* The color of the icon when idle
|
|
20
|
+
*
|
|
21
|
+
* @default 'gray'
|
|
22
|
+
*/
|
|
23
|
+
color?: MantineColor | (string & {});
|
|
16
24
|
}
|
|
17
|
-
export declare const CopyToClipboard:
|
|
25
|
+
export declare const CopyToClipboard: FunctionComponent<CopyToClipboardProps>;
|
|
18
26
|
//# sourceMappingURL=CopyToClipboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyToClipboard.d.ts","sourceRoot":"","sources":["../../../../src/components/copyToClipboard/CopyToClipboard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CopyToClipboard.d.ts","sourceRoot":"","sources":["../../../../src/components/copyToClipboard/CopyToClipboard.tsx"],"names":[],"mappings":"AACA,OAAO,EAAyB,YAAY,EAAqB,MAAM,eAAe,CAAC;AACvF,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CACxC;AAqBD,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,CAU/D,CAAC"}
|
|
@@ -14,7 +14,7 @@ var _jsxruntime = require("react/jsx-runtime");
|
|
|
14
14
|
var _plasmareacticons = require("@coveord/plasma-react-icons");
|
|
15
15
|
var _core = require("@mantine/core");
|
|
16
16
|
var CopyToClipboardButton = function(param) {
|
|
17
|
-
var value = param.value, onCopy = param.onCopy;
|
|
17
|
+
var value = param.value, onCopy = param.onCopy, color = param.color;
|
|
18
18
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.CopyButton, {
|
|
19
19
|
value: value,
|
|
20
20
|
timeout: 2000,
|
|
@@ -24,7 +24,7 @@ var CopyToClipboardButton = function(param) {
|
|
|
24
24
|
label: copied ? 'Copied' : 'Copy',
|
|
25
25
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.ActionIcon, {
|
|
26
26
|
variant: "subtle",
|
|
27
|
-
color: copied ? 'success' :
|
|
27
|
+
color: copied ? 'success' : color,
|
|
28
28
|
onClick: function() {
|
|
29
29
|
copy();
|
|
30
30
|
onCopy === null || onCopy === void 0 ? void 0 : onCopy();
|
|
@@ -44,13 +44,12 @@ var CopyToClipboard = function(_param) {
|
|
|
44
44
|
"withLabel"
|
|
45
45
|
]);
|
|
46
46
|
return withLabel ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.TextInput, {
|
|
47
|
-
classNames: {
|
|
48
|
-
input: 'var(--mantine-color-gray-7)'
|
|
49
|
-
},
|
|
50
47
|
value: others.value,
|
|
51
48
|
readOnly: true,
|
|
52
49
|
autoComplete: "off",
|
|
53
|
-
rightSection: /*#__PURE__*/ (0, _jsxruntime.jsx)(CopyToClipboardButton, _object_spread._({
|
|
50
|
+
rightSection: /*#__PURE__*/ (0, _jsxruntime.jsx)(CopyToClipboardButton, _object_spread._({
|
|
51
|
+
color: "action"
|
|
52
|
+
}, others))
|
|
54
53
|
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(CopyToClipboardButton, _object_spread._({}, others));
|
|
55
54
|
};
|
|
56
55
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/copyToClipboard/CopyToClipboard.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {ActionIcon, CopyButton, TextInput, Tooltip} from '@mantine/core';\n\nexport interface CopyToClipboardProps {\n /**\n * The value to be copied to the clipboard.\n */\n value: string;\n /**\n * Whether to display the string to be copied alongside the button.\n *\n * @default false\n */\n withLabel?: boolean;\n /**\n * Called each time the value is copied to the clipboard\n */\n onCopy?: () => void;\n}\n\nconst CopyToClipboardButton:
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/copyToClipboard/CopyToClipboard.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {ActionIcon, CopyButton, MantineColor, TextInput, Tooltip} from '@mantine/core';\nimport {FunctionComponent} from 'react';\n\nexport interface CopyToClipboardProps {\n /**\n * The value to be copied to the clipboard.\n */\n value: string;\n /**\n * Whether to display the string to be copied alongside the button.\n *\n * @default false\n */\n withLabel?: boolean;\n /**\n * Called each time the value is copied to the clipboard\n */\n onCopy?: () => void;\n /**\n * The color of the icon when idle\n *\n * @default 'gray'\n */\n color?: MantineColor | (string & {});\n}\n\nconst CopyToClipboardButton: FunctionComponent<Omit<CopyToClipboardProps, 'withLabel'>> = ({value, onCopy, color}) => (\n <CopyButton value={value} timeout={2000}>\n {({copied, copy}) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'}>\n <ActionIcon\n variant=\"subtle\"\n color={copied ? 'success' : color}\n onClick={() => {\n copy();\n onCopy?.();\n }}\n >\n {copied ? <CheckSize16Px height={16} /> : <CopySize16Px height={16} />}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\n);\n\nexport const CopyToClipboard: FunctionComponent<CopyToClipboardProps> = ({withLabel, ...others}) =>\n withLabel ? (\n <TextInput\n value={others.value}\n readOnly\n autoComplete=\"off\"\n rightSection={<CopyToClipboardButton color=\"action\" {...others} />}\n />\n ) : (\n <CopyToClipboardButton {...others} />\n );\n"],"names":["CopyToClipboard","CopyToClipboardButton","value","onCopy","color","CopyButton","timeout","copied","copy","Tooltip","label","ActionIcon","variant","onClick","CheckSize16Px","height","CopySize16Px","withLabel","others","TextInput","readOnly","autoComplete","rightSection"],"mappings":";;;;+BA8CaA;;;eAAAA;;;;;;gCA9C6B;oBAC6B;AA0BvE,IAAMC,wBAAoF;QAAEC,cAAAA,OAAOC,eAAAA,QAAQC,cAAAA;yBACvG,qBAACC,gBAAU;QAACH,OAAOA;QAAOI,SAAS;kBAC9B;gBAAEC,eAAAA,QAAQC,aAAAA;iCACP,qBAACC,aAAO;gBAACC,OAAOH,SAAS,WAAW;0BAChC,cAAA,qBAACI,gBAAU;oBACPC,SAAQ;oBACRR,OAAOG,SAAS,YAAYH;oBAC5BS,SAAS;wBACLL;wBACAL,mBAAAA,6BAAAA;oBACJ;8BAECI,uBAAS,qBAACO,+BAAa;wBAACC,QAAQ;uCAAS,qBAACC,8BAAY;wBAACD,QAAQ;;;;;;;AAO7E,IAAMf,kBAA2D;QAAEiB,mBAAAA,WAAcC;QAAdD;;WACtEA,0BACI,qBAACE,eAAS;QACNjB,OAAOgB,OAAOhB,KAAK;QACnBkB,QAAQ;QACRC,cAAa;QACbC,4BAAc,qBAACrB;YAAsBG,OAAM;WAAac;uBAG5D,qBAACjB,4CAA0BiB"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
export * from './action-icon';
|
|
1
2
|
export * from './blank-slate';
|
|
2
3
|
export * from './browser-preview';
|
|
4
|
+
export * from './button';
|
|
3
5
|
export * from './code-editor';
|
|
4
6
|
export * from './collection';
|
|
7
|
+
export * from './copyToClipboard';
|
|
5
8
|
export * from './date-range-picker';
|
|
6
|
-
export * from './sticky-footer';
|
|
7
9
|
export * from './header';
|
|
8
10
|
export * from './inline-confirm';
|
|
9
|
-
export * from './table';
|
|
10
|
-
export * from './prompt';
|
|
11
|
-
export * from './button';
|
|
12
|
-
export * from './action-icon';
|
|
13
11
|
export * from './menu';
|
|
14
|
-
export * from './
|
|
12
|
+
export * from './prompt';
|
|
13
|
+
export * from './read-only';
|
|
14
|
+
export * from './sticky-footer';
|
|
15
|
+
export * from './table';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
|
@@ -3,19 +3,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
var _export_star = require("@swc/helpers/_/_export_star");
|
|
6
|
+
_export_star._(require("./action-icon"), exports);
|
|
6
7
|
_export_star._(require("./blank-slate"), exports);
|
|
7
8
|
_export_star._(require("./browser-preview"), exports);
|
|
9
|
+
_export_star._(require("./button"), exports);
|
|
8
10
|
_export_star._(require("./code-editor"), exports);
|
|
9
11
|
_export_star._(require("./collection"), exports);
|
|
12
|
+
_export_star._(require("./copyToClipboard"), exports);
|
|
10
13
|
_export_star._(require("./date-range-picker"), exports);
|
|
11
|
-
_export_star._(require("./sticky-footer"), exports);
|
|
12
14
|
_export_star._(require("./header"), exports);
|
|
13
15
|
_export_star._(require("./inline-confirm"), exports);
|
|
14
|
-
_export_star._(require("./table"), exports);
|
|
15
|
-
_export_star._(require("./prompt"), exports);
|
|
16
|
-
_export_star._(require("./button"), exports);
|
|
17
|
-
_export_star._(require("./action-icon"), exports);
|
|
18
16
|
_export_star._(require("./menu"), exports);
|
|
19
|
-
_export_star._(require("./
|
|
17
|
+
_export_star._(require("./prompt"), exports);
|
|
18
|
+
_export_star._(require("./read-only"), exports);
|
|
19
|
+
_export_star._(require("./sticky-footer"), exports);
|
|
20
|
+
_export_star._(require("./table"), exports);
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from './blank-slate';\nexport * from './browser-preview';\nexport * from './code-editor';\nexport * from './collection';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/components/index.ts"],"sourcesContent":["export * from './action-icon';\nexport * from './blank-slate';\nexport * from './browser-preview';\nexport * from './button';\nexport * from './code-editor';\nexport * from './collection';\nexport * from './copyToClipboard';\nexport * from './date-range-picker';\nexport * from './header';\nexport * from './inline-confirm';\nexport * from './menu';\nexport * from './prompt';\nexport * from './read-only';\nexport * from './sticky-footer';\nexport * from './table';\n"],"names":[],"mappings":";;;;;uBAAc;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA;uBACA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const PasswordInput: import("@mantine/core").MantineComponent<{
|
|
2
|
+
props: import("@mantine/core").PasswordInputProps;
|
|
3
|
+
ref: HTMLInputElement;
|
|
4
|
+
stylesNames: import("@mantine/core").PasswordInputStylesNames;
|
|
5
|
+
vars: import("@mantine/core").PasswordInputCssVariables;
|
|
6
|
+
variant: import("@mantine/core").InputVariant;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=PasswordInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PasswordInput.d.ts","sourceRoot":"","sources":["../../../../src/components/read-only/PasswordInput.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa;;;;;;EAKxB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "PasswordInput", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PasswordInput;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
|
12
|
+
var _jsxruntime = require("react/jsx-runtime");
|
|
13
|
+
var _core = require("@mantine/core");
|
|
14
|
+
var _ReadOnlyInputStyles = require("./ReadOnlyInputStyles");
|
|
15
|
+
var ReadOnlyPasswordInput = _core.PasswordInput.withProps({
|
|
16
|
+
styles: _ReadOnlyInputStyles.readOnlyInputStyles
|
|
17
|
+
});
|
|
18
|
+
var PasswordInput = (0, _core.factory)(function(props, ref) {
|
|
19
|
+
if (props.readOnly && !props.disabled) {
|
|
20
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(ReadOnlyPasswordInput, _object_spread._({
|
|
21
|
+
ref: ref
|
|
22
|
+
}, props));
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.PasswordInput, _object_spread._({
|
|
25
|
+
ref: ref
|
|
26
|
+
}, props));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=PasswordInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/read-only/PasswordInput.tsx"],"sourcesContent":["import {factory, PasswordInput as MantinePasswordInput, type PasswordInputFactory} from '@mantine/core';\nimport {readOnlyInputStyles} from './ReadOnlyInputStyles';\n\nconst ReadOnlyPasswordInput = MantinePasswordInput.withProps({styles: readOnlyInputStyles});\n\nexport const PasswordInput = factory<PasswordInputFactory>((props, ref) => {\n if (props.readOnly && !props.disabled) {\n return <ReadOnlyPasswordInput ref={ref} {...props} />;\n }\n return <MantinePasswordInput ref={ref} {...props} />;\n});\n"],"names":["PasswordInput","ReadOnlyPasswordInput","MantinePasswordInput","withProps","styles","readOnlyInputStyles","factory","props","ref","readOnly","disabled"],"mappings":";;;;+BAKaA;;;eAAAA;;;;;oBAL2E;mCACtD;AAElC,IAAMC,wBAAwBC,mBAAoB,CAACC,SAAS,CAAC;IAACC,QAAQC,wCAAmB;AAAA;AAElF,IAAML,gBAAgBM,IAAAA,aAAO,EAAuB,SAACC,OAAOC;IAC/D,IAAID,MAAME,QAAQ,IAAI,CAACF,MAAMG,QAAQ,EAAE;QACnC,qBAAO,qBAACT;YAAsBO,KAAKA;WAASD;IAChD;IACA,qBAAO,qBAACL,mBAAoB;QAACM,KAAKA;OAASD;AAC/C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type MantineTheme } from '@mantine/core';
|
|
2
|
+
export declare const readOnlyInputStyles: (theme: MantineTheme) => {
|
|
3
|
+
wrapper: {
|
|
4
|
+
'--input-bd': string;
|
|
5
|
+
'--input-bg': string;
|
|
6
|
+
'--input-color': string;
|
|
7
|
+
'--input-placeholder-color': string;
|
|
8
|
+
};
|
|
9
|
+
input: {
|
|
10
|
+
cursor: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=ReadOnlyInputStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReadOnlyInputStyles.d.ts","sourceRoot":"","sources":["../../../../src/components/read-only/ReadOnlyInputStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,YAAY,EAAC,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,mBAAmB,UAAW,YAAY;;;;;;;;;;CAUrD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "readOnlyInputStyles", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return readOnlyInputStyles;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var readOnlyInputStyles = function(theme) {
|
|
12
|
+
return {
|
|
13
|
+
wrapper: {
|
|
14
|
+
'--input-bd': 'transparent',
|
|
15
|
+
'--input-bg': theme.colors.gray[2],
|
|
16
|
+
'--input-color': theme.colors.gray[7],
|
|
17
|
+
'--input-placeholder-color': theme.colors.gray[7]
|
|
18
|
+
},
|
|
19
|
+
input: {
|
|
20
|
+
cursor: 'text'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=ReadOnlyInputStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/read-only/ReadOnlyInputStyles.ts"],"sourcesContent":["import {type MantineTheme} from '@mantine/core';\n\nexport const readOnlyInputStyles = (theme: MantineTheme) => ({\n wrapper: {\n '--input-bd': 'transparent',\n '--input-bg': theme.colors.gray[2],\n '--input-color': theme.colors.gray[7],\n '--input-placeholder-color': theme.colors.gray[7],\n },\n input: {\n cursor: 'text',\n },\n});\n"],"names":["readOnlyInputStyles","theme","wrapper","colors","gray","input","cursor"],"mappings":";;;;+BAEaA;;;eAAAA;;;AAAN,IAAMA,sBAAsB,SAACC;WAAyB;QACzDC,SAAS;YACL,cAAc;YACd,cAAcD,MAAME,MAAM,CAACC,IAAI,CAAC,EAAE;YAClC,iBAAiBH,MAAME,MAAM,CAACC,IAAI,CAAC,EAAE;YACrC,6BAA6BH,MAAME,MAAM,CAACC,IAAI,CAAC,EAAE;QACrD;QACAC,OAAO;YACHC,QAAQ;QACZ;IACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const Select: import("@mantine/core").MantineComponent<{
|
|
2
|
+
props: import("@mantine/core").SelectProps;
|
|
3
|
+
ref: HTMLInputElement;
|
|
4
|
+
stylesNames: import("@mantine/core").SelectStylesNames;
|
|
5
|
+
variant: import("@mantine/core").InputVariant;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../../src/components/read-only/Select.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM;;;;;EAKjB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Select", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Select;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
|
12
|
+
var _jsxruntime = require("react/jsx-runtime");
|
|
13
|
+
var _core = require("@mantine/core");
|
|
14
|
+
var _ReadOnlyInputStyles = require("./ReadOnlyInputStyles");
|
|
15
|
+
var ReadOnlySelect = _core.Select.withProps({
|
|
16
|
+
styles: _ReadOnlyInputStyles.readOnlyInputStyles
|
|
17
|
+
});
|
|
18
|
+
var Select = (0, _core.factory)(function(props, ref) {
|
|
19
|
+
if (props.readOnly && !props.disabled) {
|
|
20
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(ReadOnlySelect, _object_spread._({
|
|
21
|
+
ref: ref
|
|
22
|
+
}, props));
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.Select, _object_spread._({
|
|
25
|
+
ref: ref
|
|
26
|
+
}, props));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=Select.js.map
|