@atlaskit/editor-toolbar 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/ui/ColorPalette/Color.compiled.css +25 -0
- package/dist/cjs/ui/ColorPalette/Color.js +76 -0
- package/dist/cjs/ui/ColorPalette/getColorMessage.js +20 -0
- package/dist/cjs/ui/ColorPalette/index.compiled.css +1 -0
- package/dist/cjs/ui/ColorPalette/index.js +118 -0
- package/dist/cjs/ui/ColorPalette/types.js +5 -0
- package/dist/cjs/ui/ColorPalette/utils.js +94 -0
- package/dist/cjs/ui/ToolbarDropdownMenu.js +43 -4
- package/dist/cjs/ui/ToolbarDropdownMenuContext.js +40 -0
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/ui/ColorPalette/Color.compiled.css +25 -0
- package/dist/es2019/ui/ColorPalette/Color.js +65 -0
- package/dist/es2019/ui/ColorPalette/getColorMessage.js +18 -0
- package/dist/es2019/ui/ColorPalette/index.compiled.css +1 -0
- package/dist/es2019/ui/ColorPalette/index.js +110 -0
- package/dist/es2019/ui/ColorPalette/types.js +1 -0
- package/dist/es2019/ui/ColorPalette/utils.js +83 -0
- package/dist/es2019/ui/ToolbarDropdownMenu.js +43 -4
- package/dist/es2019/ui/ToolbarDropdownMenuContext.js +26 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/ui/ColorPalette/Color.compiled.css +25 -0
- package/dist/esm/ui/ColorPalette/Color.js +67 -0
- package/dist/esm/ui/ColorPalette/getColorMessage.js +14 -0
- package/dist/esm/ui/ColorPalette/index.compiled.css +1 -0
- package/dist/esm/ui/ColorPalette/index.js +109 -0
- package/dist/esm/ui/ColorPalette/types.js +1 -0
- package/dist/esm/ui/ColorPalette/utils.js +84 -0
- package/dist/esm/ui/ToolbarDropdownMenu.js +41 -4
- package/dist/esm/ui/ToolbarDropdownMenuContext.js +31 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/ui/ColorPalette/Color.d.ts +11 -0
- package/dist/types/ui/ColorPalette/getColorMessage.d.ts +8 -0
- package/dist/types/ui/ColorPalette/index.d.ts +15 -0
- package/dist/types/ui/ColorPalette/types.d.ts +89 -0
- package/dist/types/ui/ColorPalette/utils.d.ts +40 -0
- package/dist/types/ui/ToolbarDropdownMenu.d.ts +3 -0
- package/dist/types/ui/ToolbarDropdownMenuContext.d.ts +12 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/ColorPalette/Color.d.ts +11 -0
- package/dist/types-ts4.5/ui/ColorPalette/getColorMessage.d.ts +8 -0
- package/dist/types-ts4.5/ui/ColorPalette/index.d.ts +15 -0
- package/dist/types-ts4.5/ui/ColorPalette/types.d.ts +89 -0
- package/dist/types-ts4.5/ui/ColorPalette/utils.d.ts +40 -0
- package/dist/types-ts4.5/ui/ToolbarDropdownMenu.d.ts +3 -0
- package/dist/types-ts4.5/ui/ToolbarDropdownMenuContext.d.ts +12 -0
- package/package.json +5 -3
- package/src/index.ts +3 -0
- package/src/ui/ColorPalette/Color.tsx +110 -0
- package/src/ui/ColorPalette/getColorMessage.ts +27 -0
- package/src/ui/ColorPalette/index.tsx +125 -0
- package/src/ui/ColorPalette/types.ts +96 -0
- package/src/ui/ColorPalette/utils.ts +102 -0
- package/src/ui/ToolbarDropdownMenu.tsx +51 -5
- package/src/ui/ToolbarDropdownMenuContext.tsx +44 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import DropdownMenu from '@atlaskit/dropdown-menu';
|
|
3
3
|
import { useToolbarUI } from '../hooks/ui-context';
|
|
4
4
|
import { ToolbarButton } from './ToolbarButton';
|
|
5
|
-
|
|
5
|
+
import { ToolbarDropdownMenuProvider, useToolbarDropdownMenu } from './ToolbarDropdownMenuContext';
|
|
6
|
+
var ToolbarDropdownMenuContent = function ToolbarDropdownMenuContent(_ref) {
|
|
6
7
|
var iconBefore = _ref.iconBefore,
|
|
7
8
|
groupLocation = _ref.groupLocation,
|
|
8
9
|
children = _ref.children,
|
|
@@ -11,6 +12,23 @@ export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
|
|
|
11
12
|
label = _ref.label;
|
|
12
13
|
var _useToolbarUI = useToolbarUI(),
|
|
13
14
|
onDropdownOpenChanged = _useToolbarUI.onDropdownOpenChanged;
|
|
15
|
+
var _useToolbarDropdownMe = useToolbarDropdownMenu(),
|
|
16
|
+
closeMenu = _useToolbarDropdownMe.closeMenu,
|
|
17
|
+
isOpen = _useToolbarDropdownMe.isOpen,
|
|
18
|
+
openMenu = _useToolbarDropdownMe.openMenu;
|
|
19
|
+
var handleOpenChange = useCallback(function (args) {
|
|
20
|
+
onDropdownOpenChanged(args);
|
|
21
|
+
if (!args.isOpen) {
|
|
22
|
+
closeMenu();
|
|
23
|
+
}
|
|
24
|
+
}, [closeMenu, onDropdownOpenChanged]);
|
|
25
|
+
var handleClick = useCallback(function () {
|
|
26
|
+
if (!isOpen) {
|
|
27
|
+
openMenu();
|
|
28
|
+
} else {
|
|
29
|
+
closeMenu();
|
|
30
|
+
}
|
|
31
|
+
}, [closeMenu, openMenu, isOpen]);
|
|
14
32
|
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
15
33
|
trigger: function trigger(triggerProps) {
|
|
16
34
|
return /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
@@ -20,7 +38,10 @@ export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
|
|
|
20
38
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
21
39
|
"aria-controls": triggerProps['aria-controls'],
|
|
22
40
|
onBlur: triggerProps.onBlur,
|
|
23
|
-
onClick:
|
|
41
|
+
onClick: function onClick(e) {
|
|
42
|
+
handleClick();
|
|
43
|
+
triggerProps.onClick && triggerProps.onClick(e);
|
|
44
|
+
},
|
|
24
45
|
onFocus: triggerProps.onFocus,
|
|
25
46
|
testId: testId,
|
|
26
47
|
iconBefore: iconBefore,
|
|
@@ -29,6 +50,22 @@ export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
|
|
|
29
50
|
label: label
|
|
30
51
|
});
|
|
31
52
|
},
|
|
32
|
-
onOpenChange:
|
|
53
|
+
onOpenChange: handleOpenChange,
|
|
54
|
+
isOpen: isOpen
|
|
33
55
|
}, children);
|
|
56
|
+
};
|
|
57
|
+
export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref2) {
|
|
58
|
+
var iconBefore = _ref2.iconBefore,
|
|
59
|
+
groupLocation = _ref2.groupLocation,
|
|
60
|
+
children = _ref2.children,
|
|
61
|
+
isDisabled = _ref2.isDisabled,
|
|
62
|
+
testId = _ref2.testId,
|
|
63
|
+
label = _ref2.label;
|
|
64
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, null, /*#__PURE__*/React.createElement(ToolbarDropdownMenuContent, {
|
|
65
|
+
iconBefore: iconBefore,
|
|
66
|
+
groupLocation: groupLocation,
|
|
67
|
+
isDisabled: isDisabled,
|
|
68
|
+
testId: testId,
|
|
69
|
+
label: label
|
|
70
|
+
}, children));
|
|
34
71
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
3
|
+
var ToolbarDropdownMenuContext = /*#__PURE__*/createContext(undefined);
|
|
4
|
+
export var useToolbarDropdownMenu = function useToolbarDropdownMenu() {
|
|
5
|
+
var context = useContext(ToolbarDropdownMenuContext);
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error('useToolbarDropdownMenu must be used within ToolbarDropdownMenuProvider');
|
|
8
|
+
}
|
|
9
|
+
return context;
|
|
10
|
+
};
|
|
11
|
+
export var ToolbarDropdownMenuProvider = function ToolbarDropdownMenuProvider(_ref) {
|
|
12
|
+
var children = _ref.children;
|
|
13
|
+
var _useState = useState(false),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
isOpen = _useState2[0],
|
|
16
|
+
setIsOpen = _useState2[1];
|
|
17
|
+
var openMenu = function openMenu() {
|
|
18
|
+
return setIsOpen(true);
|
|
19
|
+
};
|
|
20
|
+
var closeMenu = function closeMenu() {
|
|
21
|
+
setIsOpen(false);
|
|
22
|
+
};
|
|
23
|
+
var contextValue = {
|
|
24
|
+
openMenu: openMenu,
|
|
25
|
+
closeMenu: closeMenu,
|
|
26
|
+
isOpen: isOpen
|
|
27
|
+
};
|
|
28
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownMenuContext.Provider, {
|
|
29
|
+
value: contextValue
|
|
30
|
+
}, children);
|
|
31
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
|
|
|
10
10
|
export { ToolbarTooltip } from './ui/ToolbarTooltip';
|
|
11
11
|
export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
|
|
12
12
|
export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
|
|
13
|
+
export { useToolbarDropdownMenu } from './ui/ToolbarDropdownMenuContext';
|
|
13
14
|
export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
|
|
14
15
|
export { AIChatIcon } from './ui/icons/AIChatIcon';
|
|
15
16
|
export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
|
|
@@ -55,5 +56,6 @@ export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
|
|
|
55
56
|
export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
|
|
56
57
|
export { IndentIcon } from './ui/icons/IndentIcon';
|
|
57
58
|
export { OutdentIcon } from './ui/icons/OutdentIcon';
|
|
59
|
+
export { default as ColorPalette } from './ui/ColorPalette';
|
|
58
60
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
59
61
|
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { ColorProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Individual color palette item component
|
|
9
|
+
* Displays a single color swatch with tooltip and selection state
|
|
10
|
+
*/
|
|
11
|
+
export declare const Color: React.NamedExoticComponent<ColorProps>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type MessageDescriptor } from 'react-intl-next';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the appropriate internationalization message for a given color
|
|
4
|
+
* @param messages - Record of color values to message descriptors
|
|
5
|
+
* @param color - The color value to look up
|
|
6
|
+
* @returns The message descriptor or undefined if not found
|
|
7
|
+
*/
|
|
8
|
+
export default function getColorMessage(messages: Record<string | number, MessageDescriptor>, color: string): MessageDescriptor | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ColorPaletteProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* ColorPalette component for displaying a grid of selectable colors
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Responsive grid layout
|
|
8
|
+
* - Keyboard navigation support
|
|
9
|
+
* - Accessibility compliance (ARIA attributes)
|
|
10
|
+
* - Theme-aware tooltips
|
|
11
|
+
* - Design token integration
|
|
12
|
+
* - Customizable color mapping
|
|
13
|
+
*/
|
|
14
|
+
declare const ColorPalette: ({ cols, onClick, onKeyDown, selectedColor, paletteOptions, }: ColorPaletteProps) => React.JSX.Element;
|
|
15
|
+
export default ColorPalette;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type MessageDescriptor } from 'react-intl-next';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single color in the palette
|
|
5
|
+
*/
|
|
6
|
+
export interface PaletteColor {
|
|
7
|
+
/** The color value (hex, token, etc.) */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Display label for the color */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Border color for the color swatch */
|
|
12
|
+
border: string;
|
|
13
|
+
/** Optional internationalization message */
|
|
14
|
+
message?: MessageDescriptor;
|
|
15
|
+
/** Optional decorator element to display instead of checkmark */
|
|
16
|
+
decorator?: ReactElement;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Array of palette colors
|
|
20
|
+
*/
|
|
21
|
+
export type Palette = Array<PaletteColor>;
|
|
22
|
+
/**
|
|
23
|
+
* Tooltip messages for different themes
|
|
24
|
+
*/
|
|
25
|
+
export type PaletteTooltipMessages = {
|
|
26
|
+
dark: Record<string, MessageDescriptor>;
|
|
27
|
+
light: Record<string, MessageDescriptor>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for the color palette
|
|
31
|
+
*/
|
|
32
|
+
export interface PaletteOptions {
|
|
33
|
+
/** Array of colors to display */
|
|
34
|
+
palette: PaletteColor[];
|
|
35
|
+
/**
|
|
36
|
+
* Function to convert hex codes to design system tokens
|
|
37
|
+
* Different color palettes may use different mapping functions
|
|
38
|
+
*/
|
|
39
|
+
hexToPaletteColor?: (hexColor: string) => string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Tooltip messages for different color themes
|
|
42
|
+
* Consumer determines which tooltip messages to use
|
|
43
|
+
*/
|
|
44
|
+
paletteColorTooltipMessages?: PaletteTooltipMessages;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Props for the main ColorPalette component
|
|
48
|
+
*/
|
|
49
|
+
export interface ColorPaletteProps {
|
|
50
|
+
/** Currently selected color value */
|
|
51
|
+
selectedColor: string | null;
|
|
52
|
+
/** Callback when a color is clicked */
|
|
53
|
+
onClick: (value: string, label: string) => void;
|
|
54
|
+
/** Optional callback for keyboard navigation */
|
|
55
|
+
onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
|
|
56
|
+
/** Number of columns in the palette grid */
|
|
57
|
+
cols?: number;
|
|
58
|
+
/** Optional CSS class name */
|
|
59
|
+
className?: string;
|
|
60
|
+
/** Palette configuration options */
|
|
61
|
+
paletteOptions: PaletteOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Props for individual color palette items
|
|
65
|
+
*/
|
|
66
|
+
export interface ColorProps {
|
|
67
|
+
/** The color value */
|
|
68
|
+
value: string;
|
|
69
|
+
/** Display label for accessibility */
|
|
70
|
+
label: string;
|
|
71
|
+
/** Tab index for keyboard navigation */
|
|
72
|
+
tabIndex?: number;
|
|
73
|
+
/** Whether this color is currently selected */
|
|
74
|
+
isSelected?: boolean;
|
|
75
|
+
/** Click handler */
|
|
76
|
+
onClick: (value: string, label: string) => void;
|
|
77
|
+
/** Keyboard event handler */
|
|
78
|
+
onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
|
|
79
|
+
/** Border color for the swatch */
|
|
80
|
+
borderColor: string;
|
|
81
|
+
/** Color for the checkmark icon */
|
|
82
|
+
checkMarkColor?: string;
|
|
83
|
+
/** Whether to auto-focus this item */
|
|
84
|
+
autoFocus?: boolean;
|
|
85
|
+
/** Function to convert hex to palette color */
|
|
86
|
+
hexToPaletteColor?: (hexColor: string) => string | undefined;
|
|
87
|
+
/** Optional decorator element */
|
|
88
|
+
decorator?: ReactElement;
|
|
89
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PaletteColor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Default number of columns in the color picker
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_COLOR_PICKER_COLUMNS = 7;
|
|
6
|
+
/**
|
|
7
|
+
* Splits a palette array into rows based on the specified number of columns
|
|
8
|
+
* @param palette - Array of palette colors
|
|
9
|
+
* @param cols - Number of columns per row
|
|
10
|
+
* @returns Array of color rows
|
|
11
|
+
*/
|
|
12
|
+
export declare function getColorsPerRowFromPalette(palette: PaletteColor[], cols?: number): PaletteColor[][];
|
|
13
|
+
/**
|
|
14
|
+
* Finds the row and column indices of a selected color in the palette grid
|
|
15
|
+
* @param colorsPerRow - 2D array of colors organized by rows
|
|
16
|
+
* @param selectedColor - The currently selected color value
|
|
17
|
+
* @returns Object containing row and column indices
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSelectedRowAndColumn(colorsPerRow: PaletteColor[][], selectedColor: string | null): {
|
|
20
|
+
selectedRowIndex: number;
|
|
21
|
+
selectedColumnIndex: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Finds the row and column indices of a selected color in a flat palette array
|
|
25
|
+
* @param palette - Flat array of palette colors
|
|
26
|
+
* @param selectedColor - The currently selected color value
|
|
27
|
+
* @param cols - Number of columns per row
|
|
28
|
+
* @returns Object containing row and column indices
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSelectedRowAndColumnFromPalette(palette: PaletteColor[], selectedColor: string | null, cols?: number): {
|
|
31
|
+
selectedRowIndex: number;
|
|
32
|
+
selectedColumnIndex: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the actual color value from a CSS variable expression
|
|
36
|
+
* Handles both token variables and fallback values
|
|
37
|
+
* @param variableExpression - CSS variable expression (e.g., "var(--ds-background-accent-blue-subtle, #0052CC)")
|
|
38
|
+
* @returns The resolved color value or empty string if not found
|
|
39
|
+
*/
|
|
40
|
+
export declare const getTokenCSSVariableValue: (variableExpression: string) => string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
|
|
2
3
|
import { type ToolbarButtonGroupLocation } from '../types';
|
|
3
4
|
type ToolbarDropdownMenuProps = {
|
|
4
5
|
iconBefore: React.ReactNode;
|
|
@@ -7,6 +8,8 @@ type ToolbarDropdownMenuProps = {
|
|
|
7
8
|
isDisabled?: boolean;
|
|
8
9
|
testId?: string;
|
|
9
10
|
label?: string;
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
onOpenChange?: (args: OnOpenChangeArgs) => void;
|
|
10
13
|
};
|
|
11
14
|
export declare const ToolbarDropdownMenu: ({ iconBefore, groupLocation, children, isDisabled, testId, label, }: ToolbarDropdownMenuProps) => React.JSX.Element;
|
|
12
15
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ToolbarDropdownMenuContextValue {
|
|
3
|
+
openMenu: () => void;
|
|
4
|
+
closeMenu: () => void;
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const useToolbarDropdownMenu: () => ToolbarDropdownMenuContextValue;
|
|
8
|
+
interface ToolbarDropdownMenuProviderProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare const ToolbarDropdownMenuProvider: ({ children, }: ToolbarDropdownMenuProviderProps) => React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -10,6 +10,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
|
|
|
10
10
|
export { ToolbarTooltip } from './ui/ToolbarTooltip';
|
|
11
11
|
export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
|
|
12
12
|
export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
|
|
13
|
+
export { useToolbarDropdownMenu } from './ui/ToolbarDropdownMenuContext';
|
|
13
14
|
export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
|
|
14
15
|
export { AIChatIcon } from './ui/icons/AIChatIcon';
|
|
15
16
|
export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
|
|
@@ -55,5 +56,6 @@ export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
|
|
|
55
56
|
export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
|
|
56
57
|
export { IndentIcon } from './ui/icons/IndentIcon';
|
|
57
58
|
export { OutdentIcon } from './ui/icons/OutdentIcon';
|
|
59
|
+
export { default as ColorPalette } from './ui/ColorPalette';
|
|
58
60
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
59
61
|
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { ColorProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Individual color palette item component
|
|
9
|
+
* Displays a single color swatch with tooltip and selection state
|
|
10
|
+
*/
|
|
11
|
+
export declare const Color: React.NamedExoticComponent<ColorProps>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type MessageDescriptor } from 'react-intl-next';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the appropriate internationalization message for a given color
|
|
4
|
+
* @param messages - Record of color values to message descriptors
|
|
5
|
+
* @param color - The color value to look up
|
|
6
|
+
* @returns The message descriptor or undefined if not found
|
|
7
|
+
*/
|
|
8
|
+
export default function getColorMessage(messages: Record<string | number, MessageDescriptor>, color: string): MessageDescriptor | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ColorPaletteProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* ColorPalette component for displaying a grid of selectable colors
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Responsive grid layout
|
|
8
|
+
* - Keyboard navigation support
|
|
9
|
+
* - Accessibility compliance (ARIA attributes)
|
|
10
|
+
* - Theme-aware tooltips
|
|
11
|
+
* - Design token integration
|
|
12
|
+
* - Customizable color mapping
|
|
13
|
+
*/
|
|
14
|
+
declare const ColorPalette: ({ cols, onClick, onKeyDown, selectedColor, paletteOptions, }: ColorPaletteProps) => React.JSX.Element;
|
|
15
|
+
export default ColorPalette;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type MessageDescriptor } from 'react-intl-next';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single color in the palette
|
|
5
|
+
*/
|
|
6
|
+
export interface PaletteColor {
|
|
7
|
+
/** The color value (hex, token, etc.) */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Display label for the color */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Border color for the color swatch */
|
|
12
|
+
border: string;
|
|
13
|
+
/** Optional internationalization message */
|
|
14
|
+
message?: MessageDescriptor;
|
|
15
|
+
/** Optional decorator element to display instead of checkmark */
|
|
16
|
+
decorator?: ReactElement;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Array of palette colors
|
|
20
|
+
*/
|
|
21
|
+
export type Palette = Array<PaletteColor>;
|
|
22
|
+
/**
|
|
23
|
+
* Tooltip messages for different themes
|
|
24
|
+
*/
|
|
25
|
+
export type PaletteTooltipMessages = {
|
|
26
|
+
dark: Record<string, MessageDescriptor>;
|
|
27
|
+
light: Record<string, MessageDescriptor>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for the color palette
|
|
31
|
+
*/
|
|
32
|
+
export interface PaletteOptions {
|
|
33
|
+
/** Array of colors to display */
|
|
34
|
+
palette: PaletteColor[];
|
|
35
|
+
/**
|
|
36
|
+
* Function to convert hex codes to design system tokens
|
|
37
|
+
* Different color palettes may use different mapping functions
|
|
38
|
+
*/
|
|
39
|
+
hexToPaletteColor?: (hexColor: string) => string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Tooltip messages for different color themes
|
|
42
|
+
* Consumer determines which tooltip messages to use
|
|
43
|
+
*/
|
|
44
|
+
paletteColorTooltipMessages?: PaletteTooltipMessages;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Props for the main ColorPalette component
|
|
48
|
+
*/
|
|
49
|
+
export interface ColorPaletteProps {
|
|
50
|
+
/** Currently selected color value */
|
|
51
|
+
selectedColor: string | null;
|
|
52
|
+
/** Callback when a color is clicked */
|
|
53
|
+
onClick: (value: string, label: string) => void;
|
|
54
|
+
/** Optional callback for keyboard navigation */
|
|
55
|
+
onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
|
|
56
|
+
/** Number of columns in the palette grid */
|
|
57
|
+
cols?: number;
|
|
58
|
+
/** Optional CSS class name */
|
|
59
|
+
className?: string;
|
|
60
|
+
/** Palette configuration options */
|
|
61
|
+
paletteOptions: PaletteOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Props for individual color palette items
|
|
65
|
+
*/
|
|
66
|
+
export interface ColorProps {
|
|
67
|
+
/** The color value */
|
|
68
|
+
value: string;
|
|
69
|
+
/** Display label for accessibility */
|
|
70
|
+
label: string;
|
|
71
|
+
/** Tab index for keyboard navigation */
|
|
72
|
+
tabIndex?: number;
|
|
73
|
+
/** Whether this color is currently selected */
|
|
74
|
+
isSelected?: boolean;
|
|
75
|
+
/** Click handler */
|
|
76
|
+
onClick: (value: string, label: string) => void;
|
|
77
|
+
/** Keyboard event handler */
|
|
78
|
+
onKeyDown?: (value: string, label: string, event: React.KeyboardEvent) => void;
|
|
79
|
+
/** Border color for the swatch */
|
|
80
|
+
borderColor: string;
|
|
81
|
+
/** Color for the checkmark icon */
|
|
82
|
+
checkMarkColor?: string;
|
|
83
|
+
/** Whether to auto-focus this item */
|
|
84
|
+
autoFocus?: boolean;
|
|
85
|
+
/** Function to convert hex to palette color */
|
|
86
|
+
hexToPaletteColor?: (hexColor: string) => string | undefined;
|
|
87
|
+
/** Optional decorator element */
|
|
88
|
+
decorator?: ReactElement;
|
|
89
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PaletteColor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Default number of columns in the color picker
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_COLOR_PICKER_COLUMNS = 7;
|
|
6
|
+
/**
|
|
7
|
+
* Splits a palette array into rows based on the specified number of columns
|
|
8
|
+
* @param palette - Array of palette colors
|
|
9
|
+
* @param cols - Number of columns per row
|
|
10
|
+
* @returns Array of color rows
|
|
11
|
+
*/
|
|
12
|
+
export declare function getColorsPerRowFromPalette(palette: PaletteColor[], cols?: number): PaletteColor[][];
|
|
13
|
+
/**
|
|
14
|
+
* Finds the row and column indices of a selected color in the palette grid
|
|
15
|
+
* @param colorsPerRow - 2D array of colors organized by rows
|
|
16
|
+
* @param selectedColor - The currently selected color value
|
|
17
|
+
* @returns Object containing row and column indices
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSelectedRowAndColumn(colorsPerRow: PaletteColor[][], selectedColor: string | null): {
|
|
20
|
+
selectedRowIndex: number;
|
|
21
|
+
selectedColumnIndex: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Finds the row and column indices of a selected color in a flat palette array
|
|
25
|
+
* @param palette - Flat array of palette colors
|
|
26
|
+
* @param selectedColor - The currently selected color value
|
|
27
|
+
* @param cols - Number of columns per row
|
|
28
|
+
* @returns Object containing row and column indices
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSelectedRowAndColumnFromPalette(palette: PaletteColor[], selectedColor: string | null, cols?: number): {
|
|
31
|
+
selectedRowIndex: number;
|
|
32
|
+
selectedColumnIndex: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the actual color value from a CSS variable expression
|
|
36
|
+
* Handles both token variables and fallback values
|
|
37
|
+
* @param variableExpression - CSS variable expression (e.g., "var(--ds-background-accent-blue-subtle, #0052CC)")
|
|
38
|
+
* @returns The resolved color value or empty string if not found
|
|
39
|
+
*/
|
|
40
|
+
export declare const getTokenCSSVariableValue: (variableExpression: string) => string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
|
|
2
3
|
import { type ToolbarButtonGroupLocation } from '../types';
|
|
3
4
|
type ToolbarDropdownMenuProps = {
|
|
4
5
|
iconBefore: React.ReactNode;
|
|
@@ -7,6 +8,8 @@ type ToolbarDropdownMenuProps = {
|
|
|
7
8
|
isDisabled?: boolean;
|
|
8
9
|
testId?: string;
|
|
9
10
|
label?: string;
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
onOpenChange?: (args: OnOpenChangeArgs) => void;
|
|
10
13
|
};
|
|
11
14
|
export declare const ToolbarDropdownMenu: ({ iconBefore, groupLocation, children, isDisabled, testId, label, }: ToolbarDropdownMenuProps) => React.JSX.Element;
|
|
12
15
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ToolbarDropdownMenuContextValue {
|
|
3
|
+
openMenu: () => void;
|
|
4
|
+
closeMenu: () => void;
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const useToolbarDropdownMenu: () => ToolbarDropdownMenuContextValue;
|
|
8
|
+
interface ToolbarDropdownMenuProviderProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare const ToolbarDropdownMenuProvider: ({ children, }: ToolbarDropdownMenuProviderProps) => React.JSX.Element;
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"registry": "https://registry.npmjs.org/"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.3.0",
|
|
7
7
|
"description": "Common UI for Toolbars across the platform",
|
|
8
8
|
"atlassian": {
|
|
9
9
|
"team": "Editor: Jenga",
|
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
"@atlaskit/tokens": "^6.0.0",
|
|
37
37
|
"@atlaskit/tooltip": "^20.4.0",
|
|
38
38
|
"@babel/runtime": "^7.0.0",
|
|
39
|
-
"@compiled/react": "^0.18.3"
|
|
39
|
+
"@compiled/react": "^0.18.3",
|
|
40
|
+
"chromatism": "^2.6.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"react": "^18.2.0"
|
|
43
|
+
"react": "^18.2.0",
|
|
44
|
+
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@af/integration-testing": "workspace:^",
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
|
|
|
11
11
|
export { ToolbarTooltip } from './ui/ToolbarTooltip';
|
|
12
12
|
export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
|
|
13
13
|
export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
|
|
14
|
+
export { useToolbarDropdownMenu } from './ui/ToolbarDropdownMenuContext';
|
|
14
15
|
|
|
15
16
|
export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
|
|
16
17
|
export { AIChatIcon } from './ui/icons/AIChatIcon';
|
|
@@ -58,6 +59,8 @@ export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
|
|
|
58
59
|
export { IndentIcon } from './ui/icons/IndentIcon';
|
|
59
60
|
export { OutdentIcon } from './ui/icons/OutdentIcon';
|
|
60
61
|
|
|
62
|
+
export { default as ColorPalette } from './ui/ColorPalette';
|
|
63
|
+
|
|
61
64
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
62
65
|
|
|
63
66
|
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|