@atlaskit/editor-toolbar 0.3.5 → 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.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/afm-cc/tsconfig.json +0 -54
- package/afm-dev-agents/tsconfig.json +0 -54
- package/afm-jira/tsconfig.json +0 -54
- package/afm-passionfruit/tsconfig.json +0 -54
- package/afm-post-office/tsconfig.json +0 -54
- package/afm-rovo-extension/tsconfig.json +0 -54
- package/afm-townsquare/tsconfig.json +0 -54
- package/afm-volt/tsconfig.json +0 -54
- package/build/tsconfig.json +0 -17
- package/examples/basic.tsx +0 -3
- package/examples/config.jsonc +0 -8
- package/examples/toolbar/examples/ExampleManuallyComposedToolbar.tsx +0 -638
- package/examples/toolbar/examples/useExampleToolbarState.tsx +0 -86
- package/examples/toolbar-ui.tsx +0 -26
- package/src/hooks/ui-context.tsx +0 -63
- package/src/index.ts +0 -74
- package/src/types.ts +0 -3
- package/src/ui/ColorPalette/Color.tsx +0 -118
- package/src/ui/ColorPalette/getColorMessage.ts +0 -27
- package/src/ui/ColorPalette/index.tsx +0 -125
- package/src/ui/ColorPalette/types.ts +0 -96
- package/src/ui/ColorPalette/utils.ts +0 -102
- package/src/ui/Toolbar.tsx +0 -57
- package/src/ui/ToolbarButton.tsx +0 -120
- package/src/ui/ToolbarButtonGroup.tsx +0 -57
- package/src/ui/ToolbarColorSwatch.tsx +0 -37
- package/src/ui/ToolbarDropdownItem.tsx +0 -142
- package/src/ui/ToolbarDropdownItemSection.tsx +0 -21
- package/src/ui/ToolbarDropdownMenu.tsx +0 -112
- package/src/ui/ToolbarDropdownMenuContext.tsx +0 -44
- package/src/ui/ToolbarKeyboardShortcutHint.tsx +0 -11
- package/src/ui/ToolbarNestedDropdownMenu.tsx +0 -45
- package/src/ui/ToolbarSection.tsx +0 -44
- package/src/ui/ToolbarTooltip.tsx +0 -18
- package/src/ui/icons/AIAdjustLengthIcon.tsx +0 -2
- package/src/ui/icons/AICasualIcon.tsx +0 -2
- package/src/ui/icons/AIChangeToneIcon.tsx +0 -2
- package/src/ui/icons/AIChatIcon.tsx +0 -50
- package/src/ui/icons/AICommandIcon.tsx +0 -2
- package/src/ui/icons/AIHeartIcon.tsx +0 -2
- package/src/ui/icons/AILengthenIcon.tsx +0 -2
- package/src/ui/icons/AIProfessionalIcon.tsx +0 -2
- package/src/ui/icons/AIShortenIcon.tsx +0 -2
- package/src/ui/icons/AISpellcheckIcon.tsx +0 -2
- package/src/ui/icons/AISummarizeIcon.tsx +0 -2
- package/src/ui/icons/AITranslateIcon.tsx +0 -2
- package/src/ui/icons/AddIcon.tsx +0 -2
- package/src/ui/icons/AlignTextCenterIcon.tsx +0 -2
- package/src/ui/icons/AlignTextLeftIcon.tsx +0 -2
- package/src/ui/icons/AlignTextRightIcon.tsx +0 -2
- package/src/ui/icons/AppsIcon.tsx +0 -2
- package/src/ui/icons/BoldIcon.tsx +0 -2
- package/src/ui/icons/ClearFormattingIcon.tsx +0 -2
- package/src/ui/icons/CodeIcon.tsx +0 -2
- package/src/ui/icons/CommentIcon.tsx +0 -2
- package/src/ui/icons/EmojiIcon.tsx +0 -2
- package/src/ui/icons/HeadingFiveIcon.tsx +0 -2
- package/src/ui/icons/HeadingFourIcon.tsx +0 -2
- package/src/ui/icons/HeadingOneIcon.tsx +0 -2
- package/src/ui/icons/HeadingSixIcon.tsx +0 -2
- package/src/ui/icons/HeadingThreeIcon.tsx +0 -2
- package/src/ui/icons/HeadingTwoIcon.tsx +0 -2
- package/src/ui/icons/HistoryIcon.tsx +0 -2
- package/src/ui/icons/ImageIcon.tsx +0 -2
- package/src/ui/icons/IndentIcon.tsx +0 -2
- package/src/ui/icons/ItalicIcon.tsx +0 -2
- package/src/ui/icons/LayoutIcon.tsx +0 -2
- package/src/ui/icons/LinkIcon.tsx +0 -2
- package/src/ui/icons/ListBulletedIcon.tsx +0 -2
- package/src/ui/icons/ListNumberedIcon.tsx +0 -2
- package/src/ui/icons/MentionIcon.tsx +0 -2
- package/src/ui/icons/MoreItemsIcon.tsx +0 -22
- package/src/ui/icons/NestedDropdownRightIcon.tsx +0 -22
- package/src/ui/icons/OutdentIcon.tsx +0 -2
- package/src/ui/icons/PinIcon.tsx +0 -2
- package/src/ui/icons/PinnedIcon.tsx +0 -2
- package/src/ui/icons/QuoteIcon.tsx +0 -2
- package/src/ui/icons/RedoIcon.tsx +0 -2
- package/src/ui/icons/ShowMoreHorizontal.tsx +0 -22
- package/src/ui/icons/StrikeThroughIcon.tsx +0 -2
- package/src/ui/icons/SubscriptIcon.tsx +0 -31
- package/src/ui/icons/SuperscriptIcon.tsx +0 -31
- package/src/ui/icons/TableIcon.tsx +0 -2
- package/src/ui/icons/TaskIcon.tsx +0 -2
- package/src/ui/icons/TextColorIcon.tsx +0 -43
- package/src/ui/icons/TextIcon.tsx +0 -2
- package/src/ui/icons/UnderlineIcon.tsx +0 -2
- package/src/ui/icons/UndoIcon.tsx +0 -2
- package/tsconfig.app.json +0 -65
- package/tsconfig.dev.json +0 -56
- 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
|
-
};
|
package/examples/toolbar-ui.tsx
DELETED
|
@@ -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;
|
package/src/hooks/ui-context.tsx
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import type { OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
|
|
4
|
-
|
|
5
|
-
export 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
|
-
popupsMountPoint?: HTMLElement;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const ToolbarUIContext = createContext<ToolbarUIContextType>({
|
|
26
|
-
onDropdownOpenChanged: () => {},
|
|
27
|
-
preventDefaultOnMouseDown: false,
|
|
28
|
-
isDisabled: false,
|
|
29
|
-
popupsMountPoint: undefined,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Access consumer specific config and state within a toolbar component
|
|
34
|
-
*/
|
|
35
|
-
export const useToolbarUI = () => {
|
|
36
|
-
const context = useContext(ToolbarUIContext);
|
|
37
|
-
|
|
38
|
-
if (!context) {
|
|
39
|
-
throw new Error('useToolbarUI must be used within ToolbarUIContext');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return context;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
type ToolbarUIProviderProps = {
|
|
46
|
-
children: React.ReactNode;
|
|
47
|
-
} & ToolbarUIContextType;
|
|
48
|
-
|
|
49
|
-
export const ToolbarUIProvider = ({
|
|
50
|
-
children,
|
|
51
|
-
onDropdownOpenChanged,
|
|
52
|
-
preventDefaultOnMouseDown,
|
|
53
|
-
isDisabled,
|
|
54
|
-
popupsMountPoint,
|
|
55
|
-
}: ToolbarUIProviderProps) => {
|
|
56
|
-
return (
|
|
57
|
-
<ToolbarUIContext.Provider
|
|
58
|
-
value={{ onDropdownOpenChanged, preventDefaultOnMouseDown, isDisabled, popupsMountPoint }}
|
|
59
|
-
>
|
|
60
|
-
{children}
|
|
61
|
-
</ToolbarUIContext.Provider>
|
|
62
|
-
);
|
|
63
|
-
};
|
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, type ToolbarUIContextType } from './hooks/ui-context';
|
package/src/types.ts
DELETED
|
@@ -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
|
-
}
|