@scality/core-ui 0.199.0 → 0.201.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.
Files changed (38) hide show
  1. package/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -1
  2. package/dist/components/buttonv2/Buttonv2.component.js +9 -5
  3. package/dist/components/buttonv2/CopyButton.component.d.ts +1 -1
  4. package/dist/components/buttonv2/CopyButton.component.d.ts.map +1 -1
  5. package/dist/components/buttonv2/CopyButton.component.js +25 -15
  6. package/dist/components/editor/Editor.component.d.ts +17 -0
  7. package/dist/components/editor/Editor.component.d.ts.map +1 -0
  8. package/dist/components/editor/Editor.component.js +118 -0
  9. package/dist/components/editor/editorTheme.d.ts +5 -0
  10. package/dist/components/editor/editorTheme.d.ts.map +1 -0
  11. package/dist/components/editor/editorTheme.js +115 -0
  12. package/dist/components/editor/index.d.ts +3 -0
  13. package/dist/components/editor/index.d.ts.map +1 -0
  14. package/dist/components/editor/index.js +1 -0
  15. package/dist/components/iconhelper/IconHelper.d.ts.map +1 -1
  16. package/dist/components/iconhelper/IconHelper.js +0 -1
  17. package/dist/components/navbar/Navbar.component.d.ts.map +1 -1
  18. package/dist/components/navbar/Navbar.component.js +15 -10
  19. package/dist/next.d.ts +2 -0
  20. package/dist/next.d.ts.map +1 -1
  21. package/dist/next.js +1 -0
  22. package/dist/utils.d.ts +1 -0
  23. package/dist/utils.d.ts.map +1 -1
  24. package/dist/utils.js +24 -0
  25. package/package.json +7 -1
  26. package/src/lib/components/buttonv2/Buttonv2.component.tsx +8 -5
  27. package/src/lib/components/buttonv2/CopyButton.component.test.tsx +252 -0
  28. package/src/lib/components/buttonv2/CopyButton.component.tsx +28 -21
  29. package/src/lib/components/editor/Editor.component.tsx +163 -0
  30. package/src/lib/components/editor/Editor.test.tsx +295 -0
  31. package/src/lib/components/editor/editorTheme.ts +126 -0
  32. package/src/lib/components/editor/index.ts +2 -0
  33. package/src/lib/components/iconhelper/IconHelper.tsx +0 -1
  34. package/src/lib/components/navbar/Navbar.component.tsx +15 -10
  35. package/src/lib/next.ts +2 -0
  36. package/src/lib/utils.test.ts +48 -0
  37. package/src/lib/utils.ts +32 -0
  38. package/stories/editor.stories.tsx +132 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAIlD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAW,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,eAAO,MAAM,iBAAiB,oIAI7B,CAAC;AAEF,0DAA0D;AAC1D,KAAK,iBAAiB,GAAG,IAAI,CAC3B,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,GAAG,OAAO,CACjB,GAAG;IACF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,wDAAwD;AACxD,KAAK,eAAe,GAAG,iBAAiB,GAAG;IACzC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF,+EAA+E;AAC/E,KAAK,cAAc,GAAG,iBAAiB,GAAG;IACxC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GAAG,CACA;IACE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB,CACJ,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,eAAe,GAAG,cAAc,CAAC;AACrD,eAAO,MAAM,YAAY,2HA0KxB,CAAC;AACF,eAAO,MAAM,WAAW,0GAIvB,CAAC;AACF,eAAO,MAAM,UAAU;WAAwB,KAAK,CAAC,SAAS;SAS7D,CAAC;AAEF,eAAO,MAAM,YAAY;;;SAaxB,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,SAAS,EACT,GAAG,IAAI,EACR,EAAE,KAAK,2CA2CP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAKlD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAW,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,eAAO,MAAM,iBAAiB,oIAI7B,CAAC;AAEF,0DAA0D;AAC1D,KAAK,iBAAiB,GAAG,IAAI,CAC3B,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,GAAG,OAAO,CACjB,GAAG;IACF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,wDAAwD;AACxD,KAAK,eAAe,GAAG,iBAAiB,GAAG;IACzC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;CAC1C,CAAC;AAEF,+EAA+E;AAC/E,KAAK,cAAc,GAAG,iBAAiB,GAAG;IACxC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GAAG,CACA;IACE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB,CACJ,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,eAAe,GAAG,cAAc,CAAC;AACrD,eAAO,MAAM,YAAY,2HA4KxB,CAAC;AACF,eAAO,MAAM,WAAW,0GAIvB,CAAC;AACF,eAAO,MAAM,UAAU;WAAwB,KAAK,CAAC,SAAS;SAS7D,CAAC;AAEF,eAAO,MAAM,YAAY;;;SAaxB,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,SAAS,EACT,GAAG,IAAI,EACR,EAAE,KAAK,2CA2CP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import styled, { css } from 'styled-components';
3
3
  import { spacing } from '../../spacing';
4
4
  import { fontSize, fontWeight } from '../../style/theme';
5
+ import { getContrastText } from '../../utils';
5
6
  import { Loader } from '../loader/Loader.component';
6
7
  import { Tooltip } from '../tooltip/Tooltip.component';
7
8
  export const FocusVisibleStyle = css `
@@ -31,31 +32,34 @@ export const ButtonStyled = styled.button `
31
32
  white-space: nowrap;
32
33
  height: ${(props) => (props.size === 'inline' ? spacing.r24 : spacing.r32)};
33
34
  ${(props) => {
35
+ var _a;
34
36
  const brand = props.theme;
35
37
  switch (props.variant) {
36
- case 'primary':
38
+ case 'primary': {
39
+ const primaryTextColor = (_a = getContrastText(brand.buttonPrimary, brand.textPrimary, brand.textReverse)) !== null && _a !== void 0 ? _a : brand.textPrimary;
37
40
  return css `
38
41
  background: ${brand.buttonPrimary};
39
42
  background-clip: padding-box, border-box;
40
43
  border: ${spacing.r1} solid transparent;
41
44
  border-color: ${brand.buttonPrimary};
42
- color: ${brand.textPrimary};
45
+ color: ${primaryTextColor};
43
46
  &:hover:enabled {
44
47
  cursor: pointer;
45
48
  border: ${spacing.r1} solid ${brand.infoPrimary};
46
- color: ${brand.textPrimary};
49
+ color: ${primaryTextColor};
47
50
  }
48
51
  // :focus-visible is the keyboard-only version of :focus
49
52
  &:focus-visible:enabled {
50
53
  ${FocusVisibleStyle}
51
- color: ${brand.textPrimary};
54
+ color: ${primaryTextColor};
52
55
  }
53
56
  &:active:enabled {
54
57
  cursor: pointer;
55
- color: ${brand.textPrimary};
58
+ color: ${primaryTextColor};
56
59
  border: ${spacing.r1} solid ${brand.infoSecondary};
57
60
  }
58
61
  `;
62
+ }
59
63
  case 'secondary':
60
64
  return css `
61
65
  background: ${brand.buttonSecondary};
@@ -1,4 +1,4 @@
1
- import { Props } from './Buttonv2.component';
1
+ import { type Props } from './Buttonv2.component';
2
2
  export declare const COPY_STATE_IDLE = "idle";
3
3
  export declare const COPY_STATE_SUCCESS = "success";
4
4
  export declare const COPY_STATE_UNSUPPORTED = "unsupported";
@@ -1 +1 @@
1
- {"version":3,"file":"CopyButton.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/CopyButton.component.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAErD,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAC5C,eAAO,MAAM,sBAAsB,gBAAgB,CAAC;AACpD,eAAO,MAAM,YAAY;iBASQ,MAAM,WAAW,OAAO;;CAoCxD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,sDAMxB;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAC/B,GAAG,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,4CA+CnC,CAAC"}
1
+ {"version":3,"file":"CopyButton.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/CopyButton.component.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE1D,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAC5C,eAAO,MAAM,sBAAsB,gBAAgB,CAAC;AACpD,eAAO,MAAM,YAAY;iBAUQ,MAAM,WAAW,OAAO;;CA0CxD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,sDAMxB;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAC/B,GAAG,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,4CA+CnC,CAAC"}
@@ -8,6 +8,8 @@ export const COPY_STATE_UNSUPPORTED = 'unsupported';
8
8
  export const useClipboard = () => {
9
9
  const [copyStatus, setCopyStatus] = useState(COPY_STATE_IDLE);
10
10
  useEffect(() => {
11
+ if (copyStatus === COPY_STATE_IDLE)
12
+ return;
11
13
  const timer = setTimeout(() => {
12
14
  setCopyStatus(COPY_STATE_IDLE);
13
15
  }, 2000);
@@ -38,8 +40,14 @@ export const useClipboard = () => {
38
40
  }
39
41
  else {
40
42
  // Copy as plain text only
41
- navigator.clipboard.writeText(text);
42
- setCopyStatus(COPY_STATE_SUCCESS);
43
+ navigator.clipboard
44
+ .writeText(text)
45
+ .then(() => {
46
+ setCopyStatus(COPY_STATE_SUCCESS);
47
+ })
48
+ .catch(() => {
49
+ setCopyStatus(COPY_STATE_UNSUPPORTED);
50
+ });
43
51
  }
44
52
  };
45
53
  return {
@@ -49,24 +57,26 @@ export const useClipboard = () => {
49
57
  };
50
58
  export const CopyButton = ({ label, textToCopy, copyAsHtml, variant, ...props }) => {
51
59
  const { copy, copyStatus } = useClipboard();
60
+ const isSuccess = copyStatus === COPY_STATE_SUCCESS;
52
61
  return (_jsx(Button, { ...props, variant: variant === 'outline' ? 'outline' : undefined, style: {
53
- minWidth:
54
- //Just to make sure the width of the button stays the same when copied!
55
- variant === 'outline'
56
- ? (label ? label.length / 2 : 0) + 7 + 'rem'
62
+ ...props.style,
63
+ ...(isSuccess && { cursor: 'not-allowed', opacity: 0.5 }),
64
+ minWidth: variant === 'outline'
65
+ ? `${(label ? label.length / 2 : 0) + 7}rem`
57
66
  : undefined,
58
67
  }, label: variant === 'outline'
59
- ? copyStatus === COPY_STATE_SUCCESS
60
- ? `Copied${label ? ' ' + label + '' : ''}!`
61
- : `Copy${label ? ' ' + label : ''}`
62
- : undefined, icon: _jsx(Icon, { name: copyStatus === COPY_STATE_SUCCESS ? 'Check' : 'Copy', color: copyStatus === COPY_STATE_SUCCESS ? 'statusHealthy' : undefined }), disabled: copyStatus === COPY_STATE_SUCCESS || props.disabled, onClick: () => copy(textToCopy, copyAsHtml), type: "button", tooltip: variant !== 'outline'
68
+ ? isSuccess
69
+ ? `Copied${label ? ` ${label}` : ''}!`
70
+ : `Copy${label ? ` ${label}` : ''}`
71
+ : undefined, icon: _jsx(Icon, { name: isSuccess ? 'Check' : 'Copy', color: isSuccess ? 'statusHealthy' : undefined }), disabled: props.disabled, "aria-disabled": isSuccess || props.disabled, onClick: () => {
72
+ if (!isSuccess)
73
+ copy(textToCopy, copyAsHtml);
74
+ }, type: "button", tooltip: variant !== 'outline'
63
75
  ? {
64
- overlay: copyStatus === COPY_STATE_SUCCESS
76
+ overlay: isSuccess
65
77
  ? 'Copied !'
66
- : `Copy${label ? ' ' + label : ''}`,
67
- overlayStyle: {
68
- maxWidth: '20rem',
69
- },
78
+ : `Copy${label ? ` ${label}` : ''}`,
79
+ overlayStyle: { maxWidth: '20rem' },
70
80
  placement: 'top',
71
81
  }
72
82
  : undefined }));
@@ -0,0 +1,17 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ export declare function isEditAttempt(e: KeyboardEvent): boolean;
4
+ export declare function createReadOnlyTooltipExtension(): Extension;
5
+ export interface EditorProps {
6
+ value: string;
7
+ onChange?: (value: string) => void;
8
+ readOnly?: boolean;
9
+ language?: 'json' | {
10
+ name: 'json';
11
+ schema?: JSONSchema7;
12
+ };
13
+ height?: string;
14
+ width?: string;
15
+ }
16
+ export declare const Editor: ({ value, onChange, readOnly, language, height, width, }: EditorProps) => import("react/jsx-runtime").JSX.Element;
17
+ //# sourceMappingURL=Editor.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Editor.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/editor/Editor.component.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQ/C,wBAAgB,aAAa,CAAC,CAAC,EAAE,aAAa,GAAG,OAAO,CAIvD;AAED,wBAAgB,8BAA8B,IAAI,SAAS,CA4E1D;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,MAAM,GAAI,yDAOpB,WAAW,4CAiDb,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { json } from '@codemirror/lang-json';
3
+ import { ViewPlugin } from '@codemirror/view';
4
+ import CodeMirror from '@uiw/react-codemirror';
5
+ import { jsonSchema as jsonSchemaExtension } from 'codemirror-json-schema';
6
+ import { useMemo, useRef } from 'react';
7
+ import { useTheme } from 'styled-components';
8
+ import { createEditorTheme } from './editorTheme';
9
+ const EDIT_KEYS = new Set(['Backspace', 'Delete', 'Enter', 'Tab']);
10
+ export function isEditAttempt(e) {
11
+ const isTyping = !e.ctrlKey && !e.metaKey && !e.altKey && e.key.length === 1;
12
+ const isCutPaste = (e.ctrlKey || e.metaKey) && (e.key === 'x' || e.key === 'v');
13
+ return isTyping || EDIT_KEYS.has(e.key) || isCutPaste;
14
+ }
15
+ export function createReadOnlyTooltipExtension() {
16
+ return ViewPlugin.define((view) => {
17
+ let tooltip = null;
18
+ let hideTimer = null;
19
+ let wrapper = null;
20
+ const dismiss = () => {
21
+ tooltip === null || tooltip === void 0 ? void 0 : tooltip.remove();
22
+ tooltip = null;
23
+ if (hideTimer)
24
+ clearTimeout(hideTimer);
25
+ hideTimer = null;
26
+ };
27
+ const show = () => {
28
+ var _a, _b, _c;
29
+ if (hideTimer)
30
+ clearTimeout(hideTimer);
31
+ const head = view.state.selection.main.head;
32
+ const coords = view.coordsAtPos(head);
33
+ if (!coords)
34
+ return;
35
+ if (!wrapper) {
36
+ wrapper = document.createElement('div');
37
+ Object.assign(wrapper.style, {
38
+ position: 'absolute',
39
+ top: '0',
40
+ left: '0',
41
+ width: '100%',
42
+ height: '100%',
43
+ pointerEvents: 'none',
44
+ overflow: 'visible',
45
+ zIndex: '100',
46
+ });
47
+ (_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.appendChild(wrapper);
48
+ }
49
+ const parentRect = (_c = (_b = wrapper.offsetParent) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect()) !== null && _c !== void 0 ? _c : view.dom.getBoundingClientRect();
50
+ if (!tooltip) {
51
+ tooltip = document.createElement('div');
52
+ tooltip.className = 'cm-readonly-tooltip';
53
+ tooltip.textContent = 'Cannot edit in read-only editor';
54
+ tooltip.setAttribute('role', 'status');
55
+ tooltip.setAttribute('aria-live', 'polite');
56
+ Object.assign(tooltip.style, {
57
+ position: 'absolute',
58
+ padding: '4px 12px',
59
+ borderRadius: '4px',
60
+ fontSize: '12px',
61
+ pointerEvents: 'none',
62
+ whiteSpace: 'nowrap',
63
+ });
64
+ wrapper.appendChild(tooltip);
65
+ }
66
+ tooltip.style.left = `${coords.left - parentRect.left}px`;
67
+ tooltip.style.top = `${coords.bottom - parentRect.top + 4}px`;
68
+ hideTimer = setTimeout(dismiss, 2000);
69
+ };
70
+ const handler = (e) => {
71
+ if (isEditAttempt(e))
72
+ show();
73
+ };
74
+ view.dom.addEventListener('keydown', handler, true);
75
+ return {
76
+ destroy() {
77
+ view.dom.removeEventListener('keydown', handler, true);
78
+ dismiss();
79
+ wrapper === null || wrapper === void 0 ? void 0 : wrapper.remove();
80
+ },
81
+ };
82
+ });
83
+ }
84
+ export const Editor = ({ value, onChange, readOnly = false, language = 'json', height = '400px', width = '100%', }) => {
85
+ const theme = useTheme();
86
+ const editorTheme = useMemo(() => createEditorTheme(theme), [theme]);
87
+ const langName = typeof language === 'string' ? language : language.name;
88
+ const schema = typeof language === 'object' ? language.schema : undefined;
89
+ const readOnlyTooltipExt = useRef(null);
90
+ if (!readOnlyTooltipExt.current) {
91
+ readOnlyTooltipExt.current = createReadOnlyTooltipExtension();
92
+ }
93
+ const extensions = useMemo(() => {
94
+ const exts = [];
95
+ if (langName === 'json') {
96
+ if (schema) {
97
+ exts.push(...jsonSchemaExtension(schema));
98
+ }
99
+ else {
100
+ exts.push(json());
101
+ }
102
+ }
103
+ if (readOnly) {
104
+ exts.push(readOnlyTooltipExt.current);
105
+ }
106
+ return exts;
107
+ }, [langName, schema, readOnly]);
108
+ return (_jsx(CodeMirror, { value: value, height: height, width: width, extensions: extensions, onChange: onChange, readOnly: readOnly, theme: editorTheme, basicSetup: {
109
+ lineNumbers: true,
110
+ foldGutter: true,
111
+ autocompletion: true,
112
+ highlightActiveLine: true,
113
+ highlightActiveLineGutter: true,
114
+ indentOnInput: true,
115
+ bracketMatching: true,
116
+ closeBrackets: true,
117
+ } }));
118
+ };
@@ -0,0 +1,5 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ import type { CoreUITheme } from '../../style/theme';
3
+ export declare function isDarkBackground(theme: CoreUITheme): boolean;
4
+ export declare function createEditorTheme(theme: CoreUITheme): Extension;
5
+ //# sourceMappingURL=editorTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorTheme.d.ts","sourceRoot":"","sources":["../../../src/lib/components/editor/editorTheme.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAM5D;AAyBD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,CAsF/D"}
@@ -0,0 +1,115 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
3
+ import { tags } from '@lezer/highlight';
4
+ import { getLuminance } from 'polished';
5
+ import { lineColor5 } from '../../style/theme';
6
+ export function isDarkBackground(theme) {
7
+ try {
8
+ return getLuminance(theme.backgroundLevel1) < 0.5;
9
+ }
10
+ catch {
11
+ return true;
12
+ }
13
+ }
14
+ function getSyntaxColors(theme, isDark) {
15
+ if (isDark) {
16
+ return {
17
+ property: theme.statusHealthy,
18
+ string: lineColor5,
19
+ number: lineColor5,
20
+ boolean: lineColor5,
21
+ null: theme.textSecondary,
22
+ bracket: theme.textPrimary,
23
+ punctuation: theme.textPrimary,
24
+ };
25
+ }
26
+ return {
27
+ property: '#4078F2',
28
+ string: '#50A14F',
29
+ number: '#986801',
30
+ boolean: '#0184BC',
31
+ null: '#0184BC',
32
+ bracket: '#383A42',
33
+ punctuation: '#383A42',
34
+ };
35
+ }
36
+ export function createEditorTheme(theme) {
37
+ const isDark = isDarkBackground(theme);
38
+ const syntax = getSyntaxColors(theme, isDark);
39
+ const editorViewTheme = EditorView.theme({
40
+ '&': {
41
+ backgroundColor: theme.backgroundLevel1,
42
+ color: theme.textPrimary,
43
+ },
44
+ '.cm-content': {
45
+ caretColor: theme.textPrimary,
46
+ fontFamily: "'Courier New', monospace",
47
+ fontSize: '12px',
48
+ },
49
+ '.cm-cursor, .cm-dropCursor': {
50
+ borderLeftColor: theme.textPrimary,
51
+ },
52
+ '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {
53
+ backgroundColor: theme.highlight,
54
+ },
55
+ '.cm-gutters': {
56
+ backgroundColor: theme.backgroundLevel1,
57
+ color: theme.textSecondary,
58
+ border: 'none',
59
+ borderRight: `1px solid ${theme.border}`,
60
+ },
61
+ '.cm-activeLineGutter': {
62
+ backgroundColor: theme.backgroundLevel3,
63
+ },
64
+ '.cm-activeLine': {
65
+ backgroundColor: theme.backgroundLevel3,
66
+ },
67
+ '.cm-foldPlaceholder': {
68
+ backgroundColor: 'transparent',
69
+ border: 'none',
70
+ color: theme.textSecondary,
71
+ },
72
+ '.cm-diagnostic-error': {
73
+ borderLeftColor: theme.statusCritical,
74
+ },
75
+ '.cm-diagnostic-warning': {
76
+ borderLeftColor: theme.statusWarning,
77
+ },
78
+ '.cm-lintRange-error': {
79
+ backgroundImage: 'none',
80
+ textDecoration: `underline wavy ${theme.statusCritical}`,
81
+ },
82
+ '.cm-lintRange-warning': {
83
+ backgroundImage: 'none',
84
+ textDecoration: `underline wavy ${theme.statusWarning}`,
85
+ },
86
+ '.cm-tooltip': {
87
+ backgroundColor: theme.backgroundLevel3,
88
+ color: theme.textPrimary,
89
+ border: `1px solid ${theme.border}`,
90
+ },
91
+ '.cm-tooltip-lint': {
92
+ backgroundColor: theme.backgroundLevel3,
93
+ },
94
+ '.cm-panels': {
95
+ backgroundColor: theme.backgroundLevel4,
96
+ color: theme.textPrimary,
97
+ },
98
+ '.cm-readonly-tooltip': {
99
+ backgroundColor: theme.backgroundLevel3,
100
+ color: theme.textPrimary,
101
+ border: `1px solid ${theme.border}`,
102
+ },
103
+ }, { dark: isDark });
104
+ const highlightStyle = HighlightStyle.define([
105
+ { tag: tags.propertyName, color: syntax.property },
106
+ { tag: tags.string, color: syntax.string },
107
+ { tag: tags.number, color: syntax.number },
108
+ { tag: tags.bool, color: syntax.boolean },
109
+ { tag: tags.null, color: syntax.null },
110
+ { tag: tags.punctuation, color: syntax.punctuation },
111
+ { tag: tags.brace, color: syntax.bracket },
112
+ { tag: tags.squareBracket, color: syntax.bracket },
113
+ ]);
114
+ return [editorViewTheme, syntaxHighlighting(highlightStyle)];
115
+ }
@@ -0,0 +1,3 @@
1
+ export { Editor } from './Editor.component';
2
+ export type { EditorProps } from './Editor.component';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/components/editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1 @@
1
+ export { Editor } from './Editor.component';
@@ -1 +1 @@
1
- {"version":3,"file":"IconHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/components/iconhelper/IconHelper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGjD,OAAO,EAAE,QAAQ,EAAW,MAAM,8BAA8B,CAAC;AAEjE,KAAK,aAAa,GAAG;IACnB,cAAc,EAAE,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAoBF,eAAO,MAAM,QAAQ,GAAI,8EAMtB,aAAa,4CAaf,CAAC"}
1
+ {"version":3,"file":"IconHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/components/iconhelper/IconHelper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGjD,OAAO,EAAE,QAAQ,EAAW,MAAM,8BAA8B,CAAC;AAEjE,KAAK,aAAa,GAAG;IACnB,cAAc,EAAE,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAmBF,eAAO,MAAM,QAAQ,GAAI,8EAMtB,aAAa,4CAaf,CAAC"}
@@ -8,7 +8,6 @@ const HelpButton = styled.button `
8
8
  border: none;
9
9
  padding: 0;
10
10
  margin: 0;
11
- cursor: pointer;
12
11
  color: inherit;
13
12
  font: inherit; /* Inherit font sizing */
14
13
  vertical-align: text-bottom; /* Align with text */
@@ -1 +1 @@
1
- {"version":3,"file":"Navbar.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/navbar/Navbar.component.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAA6B,KAAK,KAAK,IAAI,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAEtG,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;CAChB,GAAG,WAAW,CAAC;AAChB,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,KAAK,MAAM,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAC3D,KAAK,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAC7B,KAAK,GAAG,GAAG;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,KAAK,GAAG;IAClB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAmKF,iBAAS,MAAM,CAAC,EACd,aAAa,EACb,IAAI,EACJ,IAAS,EACT,YAAiB,EACjB,GAAG,IAAI,EACR,EAAE,KAAK,2CAuDP;AAED,eAAO,MAAM,MAAM,eAAS,CAAC"}
1
+ {"version":3,"file":"Navbar.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/navbar/Navbar.component.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAA6B,KAAK,KAAK,IAAI,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAEtG,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;CAChB,GAAG,WAAW,CAAC;AAChB,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,KAAK,MAAM,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAC3D,KAAK,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAC7B,KAAK,GAAG,GAAG;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,KAAK,GAAG;IAClB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAwKF,iBAAS,MAAM,CAAC,EACd,aAAa,EACb,IAAI,EACJ,IAAS,EACT,YAAiB,EACjB,GAAG,IAAI,EACR,EAAE,KAAK,2CAuDP;AAED,eAAO,MAAM,MAAM,eAAS,CAAC"}
@@ -4,20 +4,21 @@ import styled, { css } from 'styled-components';
4
4
  import { Logo } from '../../icons/branding';
5
5
  import { spacing } from '../../spacing';
6
6
  import { fontSize, navbarHeight, navbarItemWidth } from '../../style/theme';
7
- import { getThemePropSelector } from '../../utils';
7
+ import { getContrastText, getThemePropSelector } from '../../utils';
8
8
  import { Dropdown } from '../dropdown/Dropdown.component';
9
9
  import { Icon } from '../icon/Icon.component';
10
10
  import { Button, FocusVisibleStyle } from '../buttonv2/Buttonv2.component';
11
+ const getNavbarTextColor = (props) => { var _a; return (_a = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse)) !== null && _a !== void 0 ? _a : props.theme.textPrimary; };
11
12
  const NavbarContainer = styled.div `
12
13
  height: ${navbarHeight};
13
14
  display: flex;
14
15
  justify-content: space-between;
15
16
  ${css `
16
17
  background-color: ${getThemePropSelector('navbarBackground')};
17
- color: ${getThemePropSelector('textPrimary')};
18
+ color: ${getNavbarTextColor};
18
19
  .fas,
19
20
  .sc-trigger-text {
20
- color: ${getThemePropSelector('textPrimary')};
21
+ color: ${getNavbarTextColor};
21
22
  }
22
23
  box-sizing: border-box;
23
24
  border-bottom: 0.5px solid ${(props) => props.theme.backgroundLevel2};
@@ -45,21 +46,23 @@ const NavbarTabs = styled.div `
45
46
  border-bottom: ${spacing.r2} solid transparent;
46
47
  border-top: ${spacing.r2} solid transparent;
47
48
  ${(props) => {
49
+ var _a;
48
50
  const { selectedActive } = props.theme;
51
+ const navTextColor = (_a = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse)) !== null && _a !== void 0 ? _a : props.theme.textPrimary;
49
52
  return css `
50
- color: ${getThemePropSelector('textPrimary')};
53
+ color: ${navTextColor};
51
54
  &:hover {
52
55
  background-color: ${getThemePropSelector('highlight')};
53
56
  }
54
57
  &.selected {
55
- color: ${getThemePropSelector('textPrimary')};
58
+ color: ${navTextColor};
56
59
  font-weight: bold;
57
60
  border-bottom-color: ${selectedActive};
58
61
  }
59
62
  // :focus-visible is the keyboard-only version of :focus
60
63
  &:focus-visible {
61
64
  ${FocusVisibleStyle}
62
- color: ${props.theme.textPrimary};
65
+ color: ${navTextColor};
63
66
  }
64
67
  `;
65
68
  }};
@@ -73,9 +76,10 @@ const TabItem = styled.div `
73
76
  align-items: center;
74
77
  padding: 0 ${spacing.r16};
75
78
  ${(props) => {
76
- const { textPrimary } = props.theme;
79
+ var _a;
80
+ const navTextColor = (_a = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse)) !== null && _a !== void 0 ? _a : props.theme.textPrimary;
77
81
  return css `
78
- color: ${textPrimary};
82
+ color: ${navTextColor};
79
83
  &:hover {
80
84
  border-bottom: ${spacing.r2} solid;
81
85
  border-top: ${spacing.r2} solid;
@@ -84,7 +88,7 @@ const TabItem = styled.div `
84
88
  // :focus-visible is the keyboard-only version of :focus
85
89
  &:focus-visible {
86
90
  ${FocusVisibleStyle}
87
- color: ${props.theme.textPrimary};
91
+ color: ${navTextColor};
88
92
  }
89
93
  `;
90
94
  }};
@@ -118,13 +122,14 @@ const NavbarMenuItem = styled.div `
118
122
  height: ${navbarHeight};
119
123
  font-size: ${fontSize.base};
120
124
  background-color: ${getThemePropSelector('navbarBackground')};
125
+ color: ${(props) => { var _a; return (_a = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse)) !== null && _a !== void 0 ? _a : props.theme.textPrimary; }};
121
126
  &:hover {
122
127
  background-color: ${getThemePropSelector('highlight')};
123
128
  }
124
129
  // :focus-visible is the keyboard-only version of :focus
125
130
  &:focus-visible {
126
131
  ${FocusVisibleStyle}
127
- color: ${(props) => props.theme.textPrimary};
132
+ color: ${(props) => { var _a; return (_a = getContrastText(props.theme.navbarBackground, props.theme.textPrimary, props.theme.textReverse)) !== null && _a !== void 0 ? _a : props.theme.textPrimary; }};
128
133
  }
129
134
  width: ${navbarItemWidth};
130
135
  }
package/dist/next.d.ts CHANGED
@@ -11,6 +11,8 @@ export { CoreUiThemeProvider } from './components/coreuithemeprovider/CoreUiThem
11
11
  export { Box } from './components/box/Box';
12
12
  export { Input } from './components/inputv2/inputv2';
13
13
  export { Accordion } from './components/accordion/Accordion.component';
14
+ export { Editor } from './components/editor';
15
+ export type { EditorProps } from './components/editor';
14
16
  export { Barchart, BarchartTooltip, LineTimeSerieChart, GlobalHealthBar, Sparkline, ChartLegend, ChartLegendWrapper, useChartId, useChartLegend, ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from './components/charts';
15
17
  export type { BarchartProps, BarchartBars, BarchartSortFn, BarchartTooltipFn, LineChartProps, Serie, GlobalHealthProps, Alert, UnitRange, TimeType, CategoryType, } from './components/charts';
16
18
  export type { CoreUITheme } from './style/theme';
@@ -1 +1 @@
1
- {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/lib/next.ts"],"names":[],"mappings":"AAAA,OAAO,2CAA2C,CAAC;AACnD,OAAO,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sDAAsD,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAGvE,OAAO,EACL,QAAQ,EACR,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,iBAAiB,EACjB,KAAK,EACL,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/lib/next.ts"],"names":[],"mappings":"AAAA,OAAO,2CAA2C,CAAC;AACnD,OAAO,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sDAAsD,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EACL,QAAQ,EACR,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,KAAK,EACL,iBAAiB,EACjB,KAAK,EACL,SAAS,EACT,QAAQ,EACR,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
package/dist/next.js CHANGED
@@ -12,5 +12,6 @@ export { CoreUiThemeProvider } from './components/coreuithemeprovider/CoreUiThem
12
12
  export { Box } from './components/box/Box';
13
13
  export { Input } from './components/inputv2/inputv2';
14
14
  export { Accordion } from './components/accordion/Accordion.component';
15
+ export { Editor } from './components/editor';
15
16
  // Export all chart components from the consolidated charts folder
16
17
  export { Barchart, BarchartTooltip, LineTimeSerieChart, GlobalHealthBar, Sparkline, ChartLegend, ChartLegendWrapper, useChartId, useChartLegend, ChartTooltipContainer, ChartTooltipItem, ChartTooltipHeader, ChartTooltipItemsContainer, } from './components/charts';
package/dist/utils.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const getThemeVariantSelector: () => (props: any) => any;
7
7
  /** Returns the theme color key for a given variant (e.g. for use with Icon color prop). */
8
8
  export declare const getVariantThemeKey: (variant: string) => string;
9
9
  export declare const hex2RGB: (str: string) => [number, number, number];
10
+ export declare const getContrastText: (bgColor: string, textPrimary: string, textReverse: string) => string | null;
10
11
  export declare const convertRemToPixels: (rem: number) => number;
11
12
  type FormatISONumberOptions = {
12
13
  decimals?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAYA;mCACmC;AACnC,eAAO,MAAM,oBAAoB,GAAI,QAAG,MAAM,UAAK,QAGlD,CAAC;AAEF;mCACmC;AACnC,eAAO,MAAM,uBAAuB,SAAU,UAAK,QAIlD,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MACjB,CAAC;AAErC,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAc5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,MAahD,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,MAAM,EACb,UAAS,sBAA2B,KACnC,MAoBF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAYA;mCACmC;AACnC,eAAO,MAAM,oBAAoB,GAAI,QAAG,MAAM,UAAK,QAGlD,CAAC;AAEF;mCACmC;AACnC,eAAO,MAAM,uBAAuB,SAAU,UAAK,QAIlD,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MACjB,CAAC;AAErC,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAc5D,CAAC;AAmBF,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,aAAa,MAAM,EACnB,aAAa,MAAM,KAClB,MAAM,GAAG,IASX,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,MAahD,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,MAAM,EACb,UAAS,sBAA2B,KACnC,MAoBF,CAAC"}
package/dist/utils.js CHANGED
@@ -37,6 +37,30 @@ export const hex2RGB = (str) => {
37
37
  }
38
38
  throw new Error('Invalid hex string provided');
39
39
  };
40
+ // WCAG 2.0 relative luminance
41
+ const relativeLuminance = (r, g, b) => {
42
+ const [rs, gs, bs] = [r, g, b].map((c) => {
43
+ const s = c / 255;
44
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
45
+ });
46
+ return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
47
+ };
48
+ const wcagContrastRatio = (l1, l2) => (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
49
+ const luminanceOf = (hex) => {
50
+ const [r, g, b] = hex2RGB(hex);
51
+ return relativeLuminance(r, g, b);
52
+ };
53
+ export const getContrastText = (bgColor, textPrimary, textReverse) => {
54
+ try {
55
+ const bgLum = luminanceOf(bgColor);
56
+ const primaryContrast = wcagContrastRatio(luminanceOf(textPrimary), bgLum);
57
+ const reverseContrast = wcagContrastRatio(luminanceOf(textReverse), bgLum);
58
+ return reverseContrast > primaryContrast ? textReverse : textPrimary;
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ };
40
64
  export const convertRemToPixels = (rem) => {
41
65
  if (document.documentElement &&
42
66
  rem &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scality/core-ui",
3
- "version": "0.199.0",
3
+ "version": "0.201.0",
4
4
  "description": "Scality common React component library",
5
5
  "author": "Scality Engineering",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -85,6 +85,9 @@
85
85
  }
86
86
  },
87
87
  "dependencies": {
88
+ "@codemirror/lang-json": "^6.0.2",
89
+ "@codemirror/language": "^6.12.2",
90
+ "@codemirror/view": "^6.39.15",
88
91
  "@floating-ui/dom": "^1.6.3",
89
92
  "@floating-ui/react": "^0.27.15",
90
93
  "@fortawesome/fontawesome-free": "^7.1.0",
@@ -93,7 +96,10 @@
93
96
  "@fortawesome/free-solid-svg-icons": "^7.1.0",
94
97
  "@fortawesome/react-fontawesome": "^3.1.1",
95
98
  "@js-temporal/polyfill": "^0.4.4",
99
+ "@lezer/highlight": "^1.2.3",
96
100
  "@storybook/preview-api": "^8.3.6",
101
+ "@uiw/react-codemirror": "^4.25.5",
102
+ "codemirror-json-schema": "^0.8.1",
97
103
  "downshift": "^7.0.5",
98
104
  "polished": "3.4.1",
99
105
  "pretty-bytes": "^5.6.0",