You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[LG-5094] feat(code-editor): add panel component for toolbar functionality (#3047)
* feat(CodeEditor): enhance copy button functionality and styling
- Introduced `copyButtonAppearance` prop to control the visibility of the copy button in the CodeEditor.
- Implemented styles for different copy button appearances: 'hover', 'persist', and 'none'.
- Updated tests to verify the rendering behavior of the copy button based on the new prop.
- Refactored CodeEditor component to integrate the new copy button functionality and ensure proper rendering based on user interactions.
* refactor(CodeEditor): remove unused import from CodeEditor.types.ts
- Eliminated the unused `copyButtonClassName` import to clean up the code and improve maintainability.
* feat(CodeEditor): add CodeEditorContext for internal state management
- Introduced a new `CodeEditorContext` to provide internal context values to child components, enhancing state management within the CodeEditor.
- Implemented `CodeEditorProvider` for context provisioning and `useCodeEditorContext` hook for easy access to context values.
- This addition supports better organization and encapsulation of editor-related functionalities.
* feat(CodeEditor): introduce Panel component for enhanced toolbar functionality
- Added a new `Panel` component to the CodeEditor, providing a toolbar interface with options for formatting, copying, and custom actions.
- Integrated the `Panel` into the CodeEditor, allowing for a customizable user experience with buttons for common actions like undo, redo, and download.
- Updated the README to include documentation for the new `Panel` component and its properties.
- Enhanced TypeScript definitions to support the new component and its props.
- Included storybook examples to demonstrate the usage of the `Panel` component.
* changeset
* fix(Panel): disable dark menu rendering in the Panel component
- Updated the Panel component to set `renderDarkMenu` to false, ensuring the dark menu is not rendered.
- This change improves the consistency of the user interface in light mode.
* feat(CodeEditor): integrate Panel component and enhance CodeEditor functionality
- Added the `Panel` component to the `CodeEditor`, allowing for a customizable toolbar with options for formatting, copying, and additional actions.
- Updated `CodeEditor` to accept a `panel` prop, enabling the rendering of the `Panel` within the editor.
- Enhanced TypeScript definitions to support the new `panel` prop and its interaction with the `copyButtonAppearance` prop.
- Modified styling in `useThemeExtension` to accommodate the new panel layout.
- Removed the `Panel.stories.tsx` file as part of the integration process.
* refactor(CodeEditor, Panel): reorganize props for improved clarity and consistency
- Rearranged the props in both `CodeEditor` and `Panel` components for better readability and logical grouping.
- Ensured that related props are positioned together, enhancing the overall structure of the components.
- Maintained existing functionality while improving the code organization.
* docs(CodeEditor): update README to include new `panel` prop details
- Added documentation for the optional `panel` prop in the CodeEditor, which allows rendering a toolbar interface at the top of the editor.
- Provided a description of the `Panel` component's functionality and its available options, enhancing the clarity of the README.
* test(Panel): add comprehensive unit tests for Panel component functionality
- Introduced a new test suite for the Panel component, covering various aspects including rendering, button functionality, and accessibility.
- Implemented tests for the format, copy, and secondary menu buttons, ensuring they behave as expected when interacted with.
- Verified the integration with the CodeEditor context and confirmed proper handling of props like `showFormatButton`, `showCopyButton`, and custom secondary buttons.
- Included tests for edge cases, such as handling undefined callback functions and empty custom button arrays, to enhance robustness.
* Updated changeset
* feat(CodeEditorCopyButton): enhance icon fill color handling and simplify styles
- Introduced a new `getIconFill` function to dynamically determine the icon fill color based on the theme and copied state.
- Simplified the CSS styles for the copy button by removing redundant selectors and consolidating transition properties.
- Updated the `CopyButtonTrigger` component to accept an `iconFill` prop, allowing for more flexible icon color management.
* refactor(CodeEditor): rename getContents prop for clarity
- Updated the `CodeEditor` component to rename the `getContents` prop to `getContentsToCopy`, improving clarity regarding its functionality.
- Ensured consistency with the recent changes in the `CodeEditorCopyButton` component.
* feat(CodeEditor): enhance copy button functionality and styling
- Introduced `copyButtonAppearance` prop to control the visibility of the copy button in the CodeEditor.
- Implemented styles for different copy button appearances: 'hover', 'persist', and 'none'.
- Updated tests to verify the rendering behavior of the copy button based on the new prop.
- Refactored CodeEditor component to integrate the new copy button functionality and ensure proper rendering based on user interactions.
* refactor(CodeEditor): remove unused import from CodeEditor.types.ts
- Eliminated the unused `copyButtonClassName` import to clean up the code and improve maintainability.
* refactor(CodeEditor): rename getContents prop to getContentsToCopy
- Updated the `getContents` prop in the `CodeEditorCopyButton` to `getContentsToCopy` for improved clarity regarding its purpose.
- This change aligns with recent naming conventions and enhances the overall consistency of the CodeEditor component.
* docs(CodeEditor): add SecondaryButtonConfig section to README
- Introduced a new section in the README for `SecondaryButtonConfig`, detailing its properties including `aria-label`, `glyph`, `href`, `label`, and `onClick`.
- This addition enhances documentation clarity and provides developers with comprehensive information on configuring secondary buttons in the CodeEditor component.
* fix(Panel): update copy button accessibility labels in tests
- Changed the accessibility label for the copy button in tests from 'Copy text' to 'Copy' to align with the actual implementation.
- Updated related test cases to ensure consistency and accuracy in verifying the copy button's presence and functionality.
* refactor(Panel): update panel styles for consistency and clarity
- Replaced hardcoded height with a constant for better maintainability.
- Adjusted padding values to use spacing tokens for consistency with design system.
- Renamed grid area from 'children' to 'innerContent' to improve clarity in layout structure.
* feat(Panel): add support for custom secondary button properties
- Introduced a new `disabled` property to the `SecondaryButtonConfig` interface, allowing buttons to be disabled.
- Updated the `Panel` component to handle the `disabled` state for custom secondary buttons.
- Enhanced the README documentation for `SecondaryButtonConfig` to include the new `disabled` property, improving clarity for developers.
* fix(CodeEditor): remove href from custom secondary button configuration
- Eliminated the `href` property from the custom secondary button configuration in the CodeEditor stories, streamlining the button setup.
- This change enhances clarity and aligns with the updated button properties.
* fix(Panel): update grid area naming and type definitions
- Renamed the grid area from 'innerContent' to 'inner-content' for consistency with CSS naming conventions.
- Updated type definitions in `Panel.types.ts` to use `ReactElement` and `ReactNode` directly, enhancing clarity and type safety for the `glyph` and `innerContent` properties.
- Changed the `title` property type to `ReactNode` to allow for more flexible content rendering in the panel header.
|`minHeight`_(optional)_| Sets the editor's minimum height. |`string`|`undefined`|
69
69
|`minWidth`_(optional)_| Sets the editor's minimum width. |`string`|`undefined`|
70
70
|`onChange`_(optional)_| Callback that receives the updated editor value when changes are made. |`(value: string) => void`|`undefined`|
71
+
|`panel`_(optional)_| Panel component to render at the top of the CodeEditor. Provides a toolbar interface with formatting, copying, and custom action buttons. See the Panel component documentation for available options. |`React.ReactNode`|`undefined`|
71
72
|`placeholder`_(optional)_| Value to display in the editor when it is empty. |`HTMLElement \| string`|`undefined`|
72
73
|`readOnly`_(optional)_| Enables read only mode, making the contents uneditable. |`boolean`|`false`|
73
74
|`tooltips`_(optional)_| Add tooltips to the editor content that appear on hover. |`Array<CodeEditorTooltip>`|`undefined`|
74
75
|`value`_(optional)_| Controlled value of the editor. If set, the editor will be controlled and will not update its value on change. Use `onChange` to update the value externally. |`string`|`undefined`|
75
76
|`width`_(optional)_| Sets the editor's width. If not set, the editor will be 100% width of its parent container. |`string`|`undefined`|
76
77
78
+
### `<Panel>`
79
+
80
+
The Panel component provides a toolbar interface for the CodeEditor with formatting, copying, and custom action buttons. It displays at the top of the CodeEditor and can include a title, action buttons, and custom content.
|`baseFontSize`_(optional)_| Font size of text in the panel. Controls the typography scale used for the panel title and other text elements. |`14 \| 16`|`14`|
118
+
|`customSecondaryButtons`_(optional)_| Array of custom secondary buttons to display in the secondary menu. Each button can include a label, icon, click handler, href, and aria-label for accessibility. |`Array<SecondaryButtonConfig>`|`undefined`|
119
+
|`darkMode`_(optional)_| Determines if the component appears in dark mode. When not provided, the component will inherit the dark mode state from the LeafyGreen Provider. |`boolean`|`undefined`|
120
+
|`innerContent`_(optional)_| React node to render between the title and the buttons. Can be used to add custom controls to the panel. |`React.ReactNode`|`undefined`|
121
+
|`onCopyClick`_(optional)_| Callback fired when the copy button is clicked. Called after the copy operation is attempted. |`() => void`|`undefined`|
122
+
|`onDownloadClick`_(optional)_| Callback fired when the download button in the secondary menu is clicked. Called after the download operation is attempted. |`() => void`|`undefined`|
123
+
|`onFormatClick`_(optional)_| Callback fired when the format button is clicked. Called after the formatting operation is attempted. |`() => void`|`undefined`|
124
+
|`onRedoClick`_(optional)_| Callback fired when the redo button in the secondary menu is clicked. Called after the redo operation is attempted. |`() => void`|`undefined`|
125
+
|`onUndoClick`_(optional)_| Callback fired when the undo button in the secondary menu is clicked. Called after the undo operation is attempted. |`() => void`|`undefined`|
126
+
|`onViewShortcutsClick`_(optional)_| Callback fired when the view shortcuts button in the secondary menu is clicked. Called after the view shortcuts operation is attempted. |`() => void`|`undefined`|
127
+
|`showCopyButton`_(optional)_| Determines whether to show the copy button in the panel. When enabled, users can copy the editor content to their clipboard. |`boolean`|`undefined`|
128
+
|`showFormatButton`_(optional)_| Determines whether to show the format button in the panel. When enabled and formatting is available for the current language, users can format/prettify their code. |`boolean`|`undefined`|
129
+
|`showSecondaryMenuButton`_(optional)_| Determines whether to show the secondary menu button (ellipsis icon) in the panel. When enabled, displays a menu with additional actions like undo, redo, download, and view shortcuts. |`boolean`|`undefined`|
130
+
|`title`_(optional)_| Title text to display in the panel header. Typically used to show the current language or content description. |`string`|`undefined`|
0 commit comments