@atlaskit/editor-toolbar 0.3.4 → 0.3.6

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 (122) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/hooks/ui-context.js +6 -3
  3. package/dist/cjs/ui/Toolbar.compiled.css +3 -6
  4. package/dist/cjs/ui/Toolbar.js +2 -2
  5. package/dist/cjs/ui/ToolbarButtonGroup.compiled.css +1 -2
  6. package/dist/cjs/ui/ToolbarButtonGroup.js +1 -1
  7. package/dist/cjs/ui/ToolbarSection.compiled.css +6 -1
  8. package/dist/cjs/ui/ToolbarSection.js +13 -7
  9. package/dist/es2019/hooks/ui-context.js +6 -3
  10. package/dist/es2019/ui/Toolbar.compiled.css +3 -6
  11. package/dist/es2019/ui/Toolbar.js +2 -2
  12. package/dist/es2019/ui/ToolbarButtonGroup.compiled.css +1 -2
  13. package/dist/es2019/ui/ToolbarButtonGroup.js +1 -1
  14. package/dist/es2019/ui/ToolbarSection.compiled.css +6 -1
  15. package/dist/es2019/ui/ToolbarSection.js +10 -5
  16. package/dist/esm/hooks/ui-context.js +6 -3
  17. package/dist/esm/ui/Toolbar.compiled.css +3 -6
  18. package/dist/esm/ui/Toolbar.js +2 -2
  19. package/dist/esm/ui/ToolbarButtonGroup.compiled.css +1 -2
  20. package/dist/esm/ui/ToolbarButtonGroup.js +1 -1
  21. package/dist/esm/ui/ToolbarSection.compiled.css +6 -1
  22. package/dist/esm/ui/ToolbarSection.js +10 -5
  23. package/dist/types/hooks/ui-context.d.ts +3 -2
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/ui/Toolbar.d.ts +5 -0
  26. package/dist/types/ui/ToolbarSection.d.ts +10 -2
  27. package/dist/types-ts4.5/hooks/ui-context.d.ts +3 -2
  28. package/dist/types-ts4.5/index.d.ts +1 -1
  29. package/dist/types-ts4.5/ui/Toolbar.d.ts +5 -0
  30. package/dist/types-ts4.5/ui/ToolbarSection.d.ts +10 -2
  31. package/package.json +1 -1
  32. package/afm-cc/tsconfig.json +0 -54
  33. package/afm-dev-agents/tsconfig.json +0 -54
  34. package/afm-jira/tsconfig.json +0 -54
  35. package/afm-passionfruit/tsconfig.json +0 -54
  36. package/afm-post-office/tsconfig.json +0 -54
  37. package/afm-rovo-extension/tsconfig.json +0 -54
  38. package/afm-townsquare/tsconfig.json +0 -54
  39. package/afm-volt/tsconfig.json +0 -54
  40. package/build/tsconfig.json +0 -17
  41. package/examples/basic.tsx +0 -3
  42. package/examples/config.jsonc +0 -8
  43. package/examples/toolbar/examples/ExampleManuallyComposedToolbar.tsx +0 -638
  44. package/examples/toolbar/examples/useExampleToolbarState.tsx +0 -86
  45. package/examples/toolbar-ui.tsx +0 -26
  46. package/src/hooks/ui-context.tsx +0 -60
  47. package/src/index.ts +0 -74
  48. package/src/types.ts +0 -3
  49. package/src/ui/ColorPalette/Color.tsx +0 -118
  50. package/src/ui/ColorPalette/getColorMessage.ts +0 -27
  51. package/src/ui/ColorPalette/index.tsx +0 -125
  52. package/src/ui/ColorPalette/types.ts +0 -96
  53. package/src/ui/ColorPalette/utils.ts +0 -102
  54. package/src/ui/Toolbar.tsx +0 -55
  55. package/src/ui/ToolbarButton.tsx +0 -120
  56. package/src/ui/ToolbarButtonGroup.tsx +0 -57
  57. package/src/ui/ToolbarColorSwatch.tsx +0 -37
  58. package/src/ui/ToolbarDropdownItem.tsx +0 -142
  59. package/src/ui/ToolbarDropdownItemSection.tsx +0 -21
  60. package/src/ui/ToolbarDropdownMenu.tsx +0 -112
  61. package/src/ui/ToolbarDropdownMenuContext.tsx +0 -44
  62. package/src/ui/ToolbarKeyboardShortcutHint.tsx +0 -11
  63. package/src/ui/ToolbarNestedDropdownMenu.tsx +0 -45
  64. package/src/ui/ToolbarSection.tsx +0 -24
  65. package/src/ui/ToolbarTooltip.tsx +0 -18
  66. package/src/ui/icons/AIAdjustLengthIcon.tsx +0 -2
  67. package/src/ui/icons/AICasualIcon.tsx +0 -2
  68. package/src/ui/icons/AIChangeToneIcon.tsx +0 -2
  69. package/src/ui/icons/AIChatIcon.tsx +0 -50
  70. package/src/ui/icons/AICommandIcon.tsx +0 -2
  71. package/src/ui/icons/AIHeartIcon.tsx +0 -2
  72. package/src/ui/icons/AILengthenIcon.tsx +0 -2
  73. package/src/ui/icons/AIProfessionalIcon.tsx +0 -2
  74. package/src/ui/icons/AIShortenIcon.tsx +0 -2
  75. package/src/ui/icons/AISpellcheckIcon.tsx +0 -2
  76. package/src/ui/icons/AISummarizeIcon.tsx +0 -2
  77. package/src/ui/icons/AITranslateIcon.tsx +0 -2
  78. package/src/ui/icons/AddIcon.tsx +0 -2
  79. package/src/ui/icons/AlignTextCenterIcon.tsx +0 -2
  80. package/src/ui/icons/AlignTextLeftIcon.tsx +0 -2
  81. package/src/ui/icons/AlignTextRightIcon.tsx +0 -2
  82. package/src/ui/icons/AppsIcon.tsx +0 -2
  83. package/src/ui/icons/BoldIcon.tsx +0 -2
  84. package/src/ui/icons/ClearFormattingIcon.tsx +0 -2
  85. package/src/ui/icons/CodeIcon.tsx +0 -2
  86. package/src/ui/icons/CommentIcon.tsx +0 -2
  87. package/src/ui/icons/EmojiIcon.tsx +0 -2
  88. package/src/ui/icons/HeadingFiveIcon.tsx +0 -2
  89. package/src/ui/icons/HeadingFourIcon.tsx +0 -2
  90. package/src/ui/icons/HeadingOneIcon.tsx +0 -2
  91. package/src/ui/icons/HeadingSixIcon.tsx +0 -2
  92. package/src/ui/icons/HeadingThreeIcon.tsx +0 -2
  93. package/src/ui/icons/HeadingTwoIcon.tsx +0 -2
  94. package/src/ui/icons/HistoryIcon.tsx +0 -2
  95. package/src/ui/icons/ImageIcon.tsx +0 -2
  96. package/src/ui/icons/IndentIcon.tsx +0 -2
  97. package/src/ui/icons/ItalicIcon.tsx +0 -2
  98. package/src/ui/icons/LayoutIcon.tsx +0 -2
  99. package/src/ui/icons/LinkIcon.tsx +0 -2
  100. package/src/ui/icons/ListBulletedIcon.tsx +0 -2
  101. package/src/ui/icons/ListNumberedIcon.tsx +0 -2
  102. package/src/ui/icons/MentionIcon.tsx +0 -2
  103. package/src/ui/icons/MoreItemsIcon.tsx +0 -22
  104. package/src/ui/icons/NestedDropdownRightIcon.tsx +0 -22
  105. package/src/ui/icons/OutdentIcon.tsx +0 -2
  106. package/src/ui/icons/PinIcon.tsx +0 -2
  107. package/src/ui/icons/PinnedIcon.tsx +0 -2
  108. package/src/ui/icons/QuoteIcon.tsx +0 -2
  109. package/src/ui/icons/RedoIcon.tsx +0 -2
  110. package/src/ui/icons/ShowMoreHorizontal.tsx +0 -22
  111. package/src/ui/icons/StrikeThroughIcon.tsx +0 -2
  112. package/src/ui/icons/SubscriptIcon.tsx +0 -31
  113. package/src/ui/icons/SuperscriptIcon.tsx +0 -31
  114. package/src/ui/icons/TableIcon.tsx +0 -2
  115. package/src/ui/icons/TaskIcon.tsx +0 -2
  116. package/src/ui/icons/TextColorIcon.tsx +0 -43
  117. package/src/ui/icons/TextIcon.tsx +0 -2
  118. package/src/ui/icons/UnderlineIcon.tsx +0 -2
  119. package/src/ui/icons/UndoIcon.tsx +0 -2
  120. package/tsconfig.app.json +0 -65
  121. package/tsconfig.dev.json +0 -56
  122. package/tsconfig.json +0 -18
@@ -1,86 +0,0 @@
1
- import { useState } from 'react';
2
-
3
- type TextStyle =
4
- | 'normal'
5
- | 'heading1'
6
- | 'heading2'
7
- | 'heading3'
8
- | 'heading4'
9
- | 'heading5'
10
- | 'heading6'
11
- | 'quote';
12
- type Formatting =
13
- | 'bold'
14
- | 'italic'
15
- | 'underline'
16
- | 'strikethrough'
17
- | 'code'
18
- | 'subscript'
19
- | 'superscript';
20
- type Pinning = 'none' | 'pinned';
21
- type ListOrAlignment = 'none' | 'left' | 'center' | 'right' | 'bulleted' | 'numbered';
22
-
23
- export const useExampleToolbarState = () => {
24
- const [textStyle, setTextStyle] = useState<TextStyle>('normal');
25
- const [formatting, setFormatting] = useState<Partial<Record<Formatting, boolean>>>({});
26
- const [listOrAlignment, setListOrAlignment] = useState<ListOrAlignment>('none');
27
- const [pinning, setPinning] = useState<Pinning>('none');
28
- const [lastAction, setLastAction] = useState<string | null>(null);
29
-
30
- const onSetTextStyle = (style: TextStyle) => () => {
31
- setTextStyle(style);
32
- };
33
-
34
- const onToggleFormatting = (format: Formatting) => () => {
35
- setFormatting((prev) => {
36
- if (format === 'code') {
37
- return {
38
- code: !prev.code,
39
- };
40
- } else if (prev.code) {
41
- return prev;
42
- }
43
- return {
44
- ...prev,
45
- [format]: !prev[format],
46
- };
47
- });
48
- };
49
-
50
- const onToggleListOrAlignment = (newListOrAlignment: ListOrAlignment) => () => {
51
- setListOrAlignment((prev) => {
52
- const isList = (value: ListOrAlignment) => value === 'bulleted' || value === 'numbered';
53
- if (isList(prev) && !isList(newListOrAlignment)) {
54
- return prev;
55
- }
56
- if (prev === newListOrAlignment) {
57
- return 'none';
58
- }
59
- return newListOrAlignment;
60
- });
61
- };
62
-
63
- const onTogglePinning = () => {
64
- setPinning((prev) => (prev === 'none' ? 'pinned' : 'none'));
65
- };
66
-
67
- const onClick = (action: string, callback?: () => void) => () => {
68
- callback?.();
69
- setLastAction(action);
70
- };
71
-
72
- console.log('rendering with list or alignment:', listOrAlignment);
73
-
74
- return {
75
- textStyle,
76
- onSetTextStyle,
77
- formatting,
78
- onToggleFormatting,
79
- listOrAlignment,
80
- onToggleListOrAlignment,
81
- pinning,
82
- onTogglePinning,
83
- onClick,
84
- lastAction,
85
- };
86
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
-
3
- import { cssMap } from '@atlaskit/css';
4
- import { Box } from '@atlaskit/primitives/compiled';
5
- import { token } from '@atlaskit/tokens';
6
-
7
- import { ExampleManuallyComposedToolbar } from './toolbar/examples/ExampleManuallyComposedToolbar';
8
-
9
- const styles = cssMap({
10
- container: {
11
- paddingTop: token('space.400'),
12
- paddingRight: token('space.400'),
13
- paddingBottom: token('space.400'),
14
- paddingLeft: token('space.400'),
15
- },
16
- });
17
-
18
- const App = () => {
19
- return (
20
- <Box xcss={styles.container} as="main">
21
- <ExampleManuallyComposedToolbar />
22
- </Box>
23
- );
24
- };
25
-
26
- export default App;
@@ -1,60 +0,0 @@
1
- import React, { createContext, useContext } from 'react';
2
-
3
- import type { OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
4
-
5
- type ToolbarUIContextType = {
6
- /**
7
- * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
8
- *
9
- * If the dropdown was closed programmatically, the `event` parameter will be `null`.
10
- */
11
- onDropdownOpenChanged: (args: OnOpenChangeArgs) => void;
12
-
13
- /**
14
- * Whether to prevent default behavior on mouse down events on ToolbarButton.
15
- */
16
- preventDefaultOnMouseDown?: boolean;
17
-
18
- /**
19
- * Indicates whether the toolbar is disabled when the editor is offline.
20
- */
21
- isDisabled?: boolean;
22
- };
23
-
24
- const ToolbarUIContext = createContext<ToolbarUIContextType>({
25
- onDropdownOpenChanged: () => {},
26
- preventDefaultOnMouseDown: false,
27
- isDisabled: false,
28
- });
29
-
30
- /**
31
- * Access consumer specific config and state within a toolbar component
32
- */
33
- export const useToolbarUI = () => {
34
- const context = useContext(ToolbarUIContext);
35
-
36
- if (!context) {
37
- throw new Error('useToolbarUI must be used within ToolbarUIContext');
38
- }
39
-
40
- return context;
41
- };
42
-
43
- type ToolbarUIProviderProps = {
44
- children: React.ReactNode;
45
- } & ToolbarUIContextType;
46
-
47
- export const ToolbarUIProvider = ({
48
- children,
49
- onDropdownOpenChanged,
50
- preventDefaultOnMouseDown,
51
- isDisabled,
52
- }: ToolbarUIProviderProps) => {
53
- return (
54
- <ToolbarUIContext.Provider
55
- value={{ onDropdownOpenChanged, preventDefaultOnMouseDown, isDisabled }}
56
- >
57
- {children}
58
- </ToolbarUIContext.Provider>
59
- );
60
- };
package/src/index.ts DELETED
@@ -1,74 +0,0 @@
1
- /* eslint-disable @atlaskit/editor/no-re-export */
2
- export { Toolbar, PrimaryToolbar } from './ui/Toolbar';
3
- export { ToolbarButton } from './ui/ToolbarButton';
4
- export { ToolbarButtonGroup } from './ui/ToolbarButtonGroup';
5
- export { ToolbarDropdownMenu } from './ui/ToolbarDropdownMenu';
6
- export { ToolbarDropdownItem } from './ui/ToolbarDropdownItem';
7
- export { ToolbarDropdownItemSection } from './ui/ToolbarDropdownItemSection';
8
- export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
9
- export { ToolbarKeyboardShortcutHint } from './ui/ToolbarKeyboardShortcutHint';
10
- export { ToolbarSection } from './ui/ToolbarSection';
11
- export { ToolbarTooltip } from './ui/ToolbarTooltip';
12
- export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
13
- export { useToolbarDropdownMenu } from './ui/ToolbarDropdownMenuContext';
14
-
15
- export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
16
- export { AIChatIcon } from './ui/icons/AIChatIcon';
17
- export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
18
- export { AICasualIcon } from './ui/icons/AICasualIcon';
19
- export { AIHeartIcon } from './ui/icons/AIHeartIcon';
20
- export { AIShortenIcon } from './ui/icons/AIShortenIcon';
21
- export { AISpellcheckIcon } from './ui/icons/AISpellcheckIcon';
22
- export { AIChangeToneIcon } from './ui/icons/AIChangeToneIcon';
23
- export { AILengthenIcon } from './ui/icons/AILengthenIcon';
24
- export { AISummarizeIcon } from './ui/icons/AISummarizeIcon';
25
- export { AITranslateIcon } from './ui/icons/AITranslateIcon';
26
- export { NestedDropdownRightIcon } from './ui/icons/NestedDropdownRightIcon';
27
- export { AICommandIcon } from './ui/icons/AICommandIcon';
28
- export { AddIcon } from './ui/icons/AddIcon';
29
- export { AppsIcon } from './ui/icons/AppsIcon';
30
- export { BoldIcon } from './ui/icons/BoldIcon';
31
- export { CommentIcon } from './ui/icons/CommentIcon';
32
- export { HeadingFiveIcon } from './ui/icons/HeadingFiveIcon';
33
- export { HeadingFourIcon } from './ui/icons/HeadingFourIcon';
34
- export { HeadingOneIcon } from './ui/icons/HeadingOneIcon';
35
- export { HeadingSixIcon } from './ui/icons/HeadingSixIcon';
36
- export { HeadingThreeIcon } from './ui/icons/HeadingThreeIcon';
37
- export { HeadingTwoIcon } from './ui/icons/HeadingTwoIcon';
38
- export { ItalicIcon } from './ui/icons/ItalicIcon';
39
- export { LinkIcon } from './ui/icons/LinkIcon';
40
- export { ListBulletedIcon } from './ui/icons/ListBulletedIcon';
41
- export { ListNumberedIcon } from './ui/icons/ListNumberedIcon';
42
- export { MoreItemsIcon } from './ui/icons/MoreItemsIcon';
43
- export { PinIcon } from './ui/icons/PinIcon';
44
- export { PinnedIcon } from './ui/icons/PinnedIcon';
45
- export { QuoteIcon } from './ui/icons/QuoteIcon';
46
- export { TextColorIcon } from './ui/icons/TextColorIcon';
47
- export { TextIcon } from './ui/icons/TextIcon';
48
- export { ClearFormattingIcon } from './ui/icons/ClearFormattingIcon';
49
- export { UnderlineIcon } from './ui/icons/UnderlineIcon';
50
- export { StrikeThroughIcon } from './ui/icons/StrikeThroughIcon';
51
- export { CodeIcon } from './ui/icons/CodeIcon';
52
- export { SubscriptIcon } from './ui/icons/SubscriptIcon';
53
- export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
54
- export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
55
- export { AlignTextLeftIcon } from './ui/icons/AlignTextLeftIcon';
56
- export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
57
- export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
58
- export { IndentIcon } from './ui/icons/IndentIcon';
59
- export { OutdentIcon } from './ui/icons/OutdentIcon';
60
- export { EmojiIcon } from './ui/icons/EmojiIcon';
61
- export { LayoutIcon } from './ui/icons/LayoutIcon';
62
- export { ImageIcon } from './ui/icons/ImageIcon';
63
- export { MentionIcon } from './ui/icons/MentionIcon';
64
- export { TableIcon } from './ui/icons/TableIcon';
65
- export { TaskIcon } from './ui/icons/TaskIcon';
66
- export { UndoIcon } from './ui/icons/UndoIcon';
67
- export { RedoIcon } from './ui/icons/RedoIcon';
68
- export { HistoryIcon } from './ui/icons/HistoryIcon';
69
-
70
- export { default as ColorPalette } from './ui/ColorPalette';
71
-
72
- export type { IconComponent } from './types';
73
-
74
- export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
package/src/types.ts DELETED
@@ -1,3 +0,0 @@
1
- import { type NewCoreIconProps } from '@atlaskit/icon';
2
-
3
- export type IconComponent = (props: NewCoreIconProps) => JSX.Element;
@@ -1,118 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
- import React, { useCallback, memo } from 'react';
6
-
7
- import { css, jsx } from '@compiled/react';
8
-
9
- import EditorDoneIcon from '@atlaskit/icon/core/migration/check-mark--editor-done';
10
- import { token } from '@atlaskit/tokens';
11
- import Tooltip from '@atlaskit/tooltip';
12
-
13
- import type { ColorProps } from './types';
14
-
15
- const buttonWrapperStyles = css({
16
- borderColor: 'transparent',
17
- borderStyle: 'solid',
18
- borderWidth: '1px',
19
- display: 'flex',
20
- alignItems: 'center',
21
- paddingTop: token('space.025', '2px'),
22
- paddingRight: token('space.025', '2px'),
23
- paddingBottom: token('space.025', '2px'),
24
- paddingLeft: token('space.025', '2px'),
25
- borderRadius: token('border.radius.100', '4px'),
26
- '&:focus-within, &:focus, &:hover': {
27
- borderColor: token('color.border'),
28
- },
29
- });
30
-
31
- const buttonStyles = css({
32
- height: token('space.300', '26px'),
33
- width: token('space.300', '26px'),
34
- backgroundColor: token('color.background.neutral'),
35
- padding: 0,
36
- borderRadius: token('border.radius.050', '4px'),
37
- border: `1px solid ${token('color.border.inverse')}`,
38
- cursor: 'pointer',
39
- display: 'block',
40
- position: 'relative',
41
- '&:focus': {
42
- outline: `2px solid ${token('color.border.focused')}`,
43
- outlineOffset: token('space.025', '2px'),
44
- },
45
- });
46
-
47
- /**
48
- * Individual color palette item component
49
- * Displays a single color swatch with tooltip and selection state
50
- */
51
- export const Color = memo<ColorProps>(
52
- ({
53
- autoFocus,
54
- tabIndex,
55
- value,
56
- label,
57
- isSelected,
58
- borderColor,
59
- checkMarkColor = token('color.icon.inverse', '#FFFFFF'),
60
- hexToPaletteColor,
61
- decorator,
62
- onClick,
63
- onKeyDown,
64
- }) => {
65
- const colorStyle = hexToPaletteColor ? hexToPaletteColor(value) : value;
66
-
67
- const handleMouseDown = useCallback((e: React.MouseEvent) => {
68
- e.preventDefault();
69
- }, []);
70
-
71
- const handleClick = useCallback(
72
- (e: React.MouseEvent) => {
73
- e.preventDefault();
74
- onClick(value, label);
75
- },
76
- [onClick, value, label],
77
- );
78
-
79
- const handleKeyDown = useCallback(
80
- (e: React.KeyboardEvent) => {
81
- if (!onKeyDown) {
82
- return;
83
- }
84
- e.preventDefault();
85
- onKeyDown(value, label, e);
86
- },
87
- [onKeyDown, value, label],
88
- );
89
-
90
- return (
91
- <Tooltip content={label}>
92
- <span css={buttonWrapperStyles}>
93
- <button
94
- type="button"
95
- css={buttonStyles}
96
- aria-label={label}
97
- role="radio"
98
- aria-checked={isSelected}
99
- onClick={handleClick}
100
- onKeyDown={handleKeyDown}
101
- onMouseDown={handleMouseDown}
102
- tabIndex={tabIndex}
103
- style={{
104
- backgroundColor: colorStyle || token('color.background.input', '#FFFFFF'),
105
- border: `1px solid ${borderColor}`,
106
- }}
107
- autoFocus={autoFocus}
108
- >
109
- {!decorator && isSelected && (
110
- <EditorDoneIcon LEGACY_primaryColor={checkMarkColor} label="" />
111
- )}
112
- {decorator}
113
- </button>
114
- </span>
115
- </Tooltip>
116
- );
117
- },
118
- );
@@ -1,27 +0,0 @@
1
- import { type MessageDescriptor } from 'react-intl-next';
2
-
3
- /**
4
- * Retrieves the appropriate internationalization message for a given color
5
- * @param messages - Record of color values to message descriptors
6
- * @param color - The color value to look up
7
- * @returns The message descriptor or undefined if not found
8
- */
9
- export default function getColorMessage(
10
- messages: Record<string | number, MessageDescriptor>,
11
- color: string,
12
- ): MessageDescriptor | undefined {
13
- const message = messages[color as keyof typeof messages];
14
-
15
- if (!message) {
16
- // eslint-disable-next-line no-console
17
- console.warn(
18
- `Color palette does not have an internationalization message for color ${color.toUpperCase()}.
19
- You must add a message description to properly translate this color.
20
- Using current label as default message.
21
- This could have happened when someone changed the 'colorPalette' from 'adf-schema' without updating this file.
22
- `,
23
- );
24
- }
25
-
26
- return message;
27
- }
@@ -1,125 +0,0 @@
1
- import React, { useMemo } from 'react';
2
-
3
- import chromatism from 'chromatism';
4
- import { useIntl } from 'react-intl-next';
5
-
6
- import { cssMap } from '@atlaskit/css';
7
- import { Box } from '@atlaskit/primitives/compiled';
8
- import { token, useThemeObserver } from '@atlaskit/tokens';
9
-
10
- import { Color } from './Color';
11
- import getColorMessage from './getColorMessage';
12
- import type { ColorPaletteProps } from './types';
13
- import {
14
- DEFAULT_COLOR_PICKER_COLUMNS,
15
- getColorsPerRowFromPalette,
16
- getTokenCSSVariableValue,
17
- } from './utils';
18
-
19
- const styles = cssMap({
20
- paletteWrapper: {
21
- display: 'flex',
22
- },
23
- });
24
-
25
- /**
26
- * For a given color pick the color from a list of colors with
27
- * the highest contrast
28
- *
29
- * @param color color string, supports HEX, RGB, RGBA etc.
30
- * @param useIconToken boolean, describes if a token should be used for the icon color
31
- * @return Highest contrast color in pool
32
- */
33
- function getCheckMarkColor(color: string, useIconToken: boolean): string {
34
- const tokenVal = getTokenCSSVariableValue(color);
35
- const colorValue = !!tokenVal ? tokenVal : color;
36
-
37
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
38
- const contrastColor = ['#FFFFFF', '#42526E'].sort(
39
- (a, b) => chromatism.difference(b, colorValue) - chromatism.difference(a, colorValue),
40
- )[0];
41
-
42
- if (!useIconToken) {
43
- return contrastColor;
44
- }
45
-
46
- // Use of these token comes from guidance from designers in the Design System team
47
- // they are only intended for use with text colors (and there are different tokens
48
- // planned to be used when this extended to be used with other palettes).
49
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
50
- return contrastColor === '#FFFFFF' ? token('color.icon.inverse') : token('color.icon');
51
- }
52
-
53
- /**
54
- * ColorPalette component for displaying a grid of selectable colors
55
- *
56
- * Features:
57
- * - Responsive grid layout
58
- * - Keyboard navigation support
59
- * - Accessibility compliance (ARIA attributes)
60
- * - Theme-aware tooltips
61
- * - Design token integration
62
- * - Customizable color mapping
63
- */
64
- const ColorPalette = ({
65
- cols = DEFAULT_COLOR_PICKER_COLUMNS,
66
- onClick,
67
- onKeyDown,
68
- selectedColor,
69
- paletteOptions,
70
- }: ColorPaletteProps) => {
71
- const { formatMessage } = useIntl();
72
- const { palette, hexToPaletteColor, paletteColorTooltipMessages } = paletteOptions;
73
-
74
- const { colorMode: tokenTheme } = useThemeObserver();
75
- const useIconToken = !!hexToPaletteColor;
76
-
77
- const colorsPerRow = useMemo(() => {
78
- return getColorsPerRowFromPalette(palette, cols);
79
- }, [palette, cols]);
80
-
81
- return (
82
- <>
83
- {colorsPerRow.map((row) => (
84
- <Box xcss={styles.paletteWrapper} key={`row-first-color-${row[0].value}`} role="radiogroup">
85
- {row.map(({ value, label, border, message, decorator }) => {
86
- let tooltipMessage = message;
87
-
88
- // Override with theme-specific tooltip messages if provided
89
- if (paletteColorTooltipMessages) {
90
- if (tokenTheme === 'dark') {
91
- tooltipMessage = getColorMessage(
92
- paletteColorTooltipMessages.dark,
93
- value.toUpperCase(),
94
- );
95
- }
96
- if (tokenTheme === 'light') {
97
- tooltipMessage = getColorMessage(
98
- paletteColorTooltipMessages.light,
99
- value.toUpperCase(),
100
- );
101
- }
102
- }
103
-
104
- return (
105
- <Color
106
- key={value}
107
- value={value}
108
- borderColor={border}
109
- label={tooltipMessage ? formatMessage(tooltipMessage) : label}
110
- onClick={onClick}
111
- onKeyDown={onKeyDown}
112
- isSelected={value === selectedColor}
113
- checkMarkColor={getCheckMarkColor(value, useIconToken)}
114
- hexToPaletteColor={hexToPaletteColor}
115
- decorator={decorator}
116
- />
117
- );
118
- })}
119
- </Box>
120
- ))}
121
- </>
122
- );
123
- };
124
-
125
- export default ColorPalette;
@@ -1,96 +0,0 @@
1
- import { type ReactElement } from 'react';
2
-
3
- import { type MessageDescriptor } from 'react-intl-next';
4
-
5
- /**
6
- * Represents a single color in the palette
7
- */
8
- export interface PaletteColor {
9
- /** The color value (hex, token, etc.) */
10
- value: string;
11
- /** Display label for the color */
12
- label: string;
13
- /** Border color for the color swatch */
14
- border: string;
15
- /** Optional internationalization message */
16
- message?: MessageDescriptor;
17
- /** Optional decorator element to display instead of checkmark */
18
- decorator?: ReactElement;
19
- }
20
-
21
- /**
22
- * Array of palette colors
23
- */
24
- export type Palette = Array<PaletteColor>;
25
-
26
- /**
27
- * Tooltip messages for different themes
28
- */
29
- export type PaletteTooltipMessages = {
30
- dark: Record<string, MessageDescriptor>;
31
- light: Record<string, MessageDescriptor>;
32
- };
33
-
34
- /**
35
- * Configuration options for the color palette
36
- */
37
- export interface PaletteOptions {
38
- /** Array of colors to display */
39
- palette: PaletteColor[];
40
- /**
41
- * Function to convert hex codes to design system tokens
42
- * Different color palettes may use different mapping functions
43
- */
44
- hexToPaletteColor?: (hexColor: string) => string | undefined;
45
- /**
46
- * Tooltip messages for different color themes
47
- * Consumer determines which tooltip messages to use
48
- */
49
- paletteColorTooltipMessages?: PaletteTooltipMessages;
50
- }
51
-
52
- /**
53
- * Props for the main ColorPalette component
54
- */
55
- export interface ColorPaletteProps {
56
- /** Currently selected color value */
57
- selectedColor: string | null;
58
- /** Callback when a color is clicked */
59
- onClick: (value: string, label: string) => void;
60
- /** Optional callback for keyboard navigation */
61
- onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
62
- /** Number of columns in the palette grid */
63
- cols?: number;
64
- /** Optional CSS class name */
65
- className?: string;
66
- /** Palette configuration options */
67
- paletteOptions: PaletteOptions;
68
- }
69
-
70
- /**
71
- * Props for individual color palette items
72
- */
73
- export interface ColorProps {
74
- /** The color value */
75
- value: string;
76
- /** Display label for accessibility */
77
- label: string;
78
- /** Tab index for keyboard navigation */
79
- tabIndex?: number;
80
- /** Whether this color is currently selected */
81
- isSelected?: boolean;
82
- /** Click handler */
83
- onClick: (value: string, label: string) => void;
84
- /** Keyboard event handler */
85
- onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
86
- /** Border color for the swatch */
87
- borderColor: string;
88
- /** Color for the checkmark icon */
89
- checkMarkColor?: string;
90
- /** Whether to auto-focus this item */
91
- autoFocus?: boolean;
92
- /** Function to convert hex to palette color */
93
- hexToPaletteColor?: (hexColor: string) => string | undefined;
94
- /** Optional decorator element */
95
- decorator?: ReactElement;
96
- }