@apify/ui-library 0.51.6-featurepublishuilibrary-0a4729.38266
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/.eslintrc +39 -0
- package/.stylelintrc +12 -0
- package/CHANGELOG.md +2804 -0
- package/README.md +15 -0
- package/dist/src/components/action_link.d.ts +5 -0
- package/dist/src/components/action_link.d.ts.map +1 -0
- package/dist/src/components/action_link.jsx +35 -0
- package/dist/src/components/action_link.jsx.map +1 -0
- package/dist/src/components/actor_template_card.d.ts +10 -0
- package/dist/src/components/actor_template_card.d.ts.map +1 -0
- package/dist/src/components/actor_template_card.jsx +73 -0
- package/dist/src/components/actor_template_card.jsx.map +1 -0
- package/dist/src/components/badge.d.ts +26 -0
- package/dist/src/components/badge.d.ts.map +1 -0
- package/dist/src/components/badge.jsx +96 -0
- package/dist/src/components/badge.jsx.map +1 -0
- package/dist/src/components/banner.d.ts +11 -0
- package/dist/src/components/banner.d.ts.map +1 -0
- package/dist/src/components/banner.jsx +73 -0
- package/dist/src/components/banner.jsx.map +1 -0
- package/dist/src/components/blog_article.d.ts +9 -0
- package/dist/src/components/blog_article.d.ts.map +1 -0
- package/dist/src/components/blog_article.jsx +73 -0
- package/dist/src/components/blog_article.jsx.map +1 -0
- package/dist/src/components/box.d.ts +41 -0
- package/dist/src/components/box.d.ts.map +1 -0
- package/dist/src/components/box.jsx +48 -0
- package/dist/src/components/box.jsx.map +1 -0
- package/dist/src/components/button.d.ts +35 -0
- package/dist/src/components/button.d.ts.map +1 -0
- package/dist/src/components/button.jsx +193 -0
- package/dist/src/components/button.jsx.map +1 -0
- package/dist/src/components/chip.d.ts +52 -0
- package/dist/src/components/chip.d.ts.map +1 -0
- package/dist/src/components/chip.jsx +89 -0
- package/dist/src/components/chip.jsx.map +1 -0
- package/dist/src/components/code/action_button.d.ts +11 -0
- package/dist/src/components/code/action_button.d.ts.map +1 -0
- package/dist/src/components/code/action_button.jsx +67 -0
- package/dist/src/components/code/action_button.jsx.map +1 -0
- package/dist/src/components/code/code_block/code_block.d.ts +38 -0
- package/dist/src/components/code/code_block/code_block.d.ts.map +1 -0
- package/dist/src/components/code/code_block/code_block.jsx +99 -0
- package/dist/src/components/code/code_block/code_block.jsx.map +1 -0
- package/dist/src/components/code/code_block/code_block.styled.d.ts +13 -0
- package/dist/src/components/code/code_block/code_block.styled.d.ts.map +1 -0
- package/dist/src/components/code/code_block/code_block.styled.jsx +215 -0
- package/dist/src/components/code/code_block/code_block.styled.jsx.map +1 -0
- package/dist/src/components/code/code_block/utils.d.ts +2 -0
- package/dist/src/components/code/code_block/utils.d.ts.map +1 -0
- package/dist/src/components/code/code_block/utils.js +20 -0
- package/dist/src/components/code/code_block/utils.js.map +1 -0
- package/dist/src/components/code/index.d.ts +4 -0
- package/dist/src/components/code/index.d.ts.map +1 -0
- package/dist/src/components/code/index.js +4 -0
- package/dist/src/components/code/index.js.map +1 -0
- package/dist/src/components/code/inline_code/inline_code.d.ts +11 -0
- package/dist/src/components/code/inline_code/inline_code.d.ts.map +1 -0
- package/dist/src/components/code/inline_code/inline_code.jsx +24 -0
- package/dist/src/components/code/inline_code/inline_code.jsx.map +1 -0
- package/dist/src/components/code/one_line_code/one_line_code.d.ts +27 -0
- package/dist/src/components/code/one_line_code/one_line_code.d.ts.map +1 -0
- package/dist/src/components/code/one_line_code/one_line_code.jsx +157 -0
- package/dist/src/components/code/one_line_code/one_line_code.jsx.map +1 -0
- package/dist/src/components/code/syntax_highlighter.d.ts +16 -0
- package/dist/src/components/code/syntax_highlighter.d.ts.map +1 -0
- package/dist/src/components/code/syntax_highlighter.jsx +94 -0
- package/dist/src/components/code/syntax_highlighter.jsx.map +1 -0
- package/dist/src/components/color_wheel_gradient.d.ts +9 -0
- package/dist/src/components/color_wheel_gradient.d.ts.map +1 -0
- package/dist/src/components/color_wheel_gradient.jsx +23 -0
- package/dist/src/components/color_wheel_gradient.jsx.map +1 -0
- package/dist/src/components/floating/index.d.ts +4 -0
- package/dist/src/components/floating/index.d.ts.map +1 -0
- package/dist/src/components/floating/index.js +4 -0
- package/dist/src/components/floating/index.js.map +1 -0
- package/dist/src/components/floating/menu.d.ts +33 -0
- package/dist/src/components/floating/menu.d.ts.map +1 -0
- package/dist/src/components/floating/menu.jsx +95 -0
- package/dist/src/components/floating/menu.jsx.map +1 -0
- package/dist/src/components/floating/menu_common.d.ts +42 -0
- package/dist/src/components/floating/menu_common.d.ts.map +1 -0
- package/dist/src/components/floating/menu_common.jsx +20 -0
- package/dist/src/components/floating/menu_common.jsx.map +1 -0
- package/dist/src/components/floating/menu_components.d.ts +29 -0
- package/dist/src/components/floating/menu_components.d.ts.map +1 -0
- package/dist/src/components/floating/menu_components.jsx +73 -0
- package/dist/src/components/floating/menu_components.jsx.map +1 -0
- package/dist/src/components/image.d.ts +12 -0
- package/dist/src/components/image.d.ts.map +1 -0
- package/dist/src/components/image.jsx +8 -0
- package/dist/src/components/image.jsx.map +1 -0
- package/dist/src/components/index.d.ts +21 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +21 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/link.d.ts +24 -0
- package/dist/src/components/link.d.ts.map +1 -0
- package/dist/src/components/link.jsx +67 -0
- package/dist/src/components/link.jsx.map +1 -0
- package/dist/src/components/message.d.ts +31 -0
- package/dist/src/components/message.d.ts.map +1 -0
- package/dist/src/components/message.jsx +105 -0
- package/dist/src/components/message.jsx.map +1 -0
- package/dist/src/components/readme_renderer/index.d.ts +4 -0
- package/dist/src/components/readme_renderer/index.d.ts.map +1 -0
- package/dist/src/components/readme_renderer/index.js +4 -0
- package/dist/src/components/readme_renderer/index.js.map +1 -0
- package/dist/src/components/readme_renderer/pythonize_value.d.ts +3 -0
- package/dist/src/components/readme_renderer/pythonize_value.d.ts.map +1 -0
- package/dist/src/components/readme_renderer/pythonize_value.js +81 -0
- package/dist/src/components/readme_renderer/pythonize_value.js.map +1 -0
- package/dist/src/components/readme_renderer/table_of_contents.d.ts +10 -0
- package/dist/src/components/readme_renderer/table_of_contents.d.ts.map +1 -0
- package/dist/src/components/readme_renderer/table_of_contents.jsx +197 -0
- package/dist/src/components/readme_renderer/table_of_contents.jsx.map +1 -0
- package/dist/src/components/readme_renderer/utils.d.ts +6 -0
- package/dist/src/components/readme_renderer/utils.d.ts.map +1 -0
- package/dist/src/components/readme_renderer/utils.jsx +42 -0
- package/dist/src/components/readme_renderer/utils.jsx.map +1 -0
- package/dist/src/components/simple_markdown/index.d.ts +3 -0
- package/dist/src/components/simple_markdown/index.d.ts.map +1 -0
- package/dist/src/components/simple_markdown/index.jsx +3 -0
- package/dist/src/components/simple_markdown/index.jsx.map +1 -0
- package/dist/src/components/simple_markdown/simple_markdown.d.ts +16 -0
- package/dist/src/components/simple_markdown/simple_markdown.d.ts.map +1 -0
- package/dist/src/components/simple_markdown/simple_markdown.jsx +137 -0
- package/dist/src/components/simple_markdown/simple_markdown.jsx.map +1 -0
- package/dist/src/components/simple_markdown/simple_markdown_components.d.ts +26 -0
- package/dist/src/components/simple_markdown/simple_markdown_components.d.ts.map +1 -0
- package/dist/src/components/simple_markdown/simple_markdown_components.jsx +193 -0
- package/dist/src/components/simple_markdown/simple_markdown_components.jsx.map +1 -0
- package/dist/src/components/tag.d.ts +38 -0
- package/dist/src/components/tag.d.ts.map +1 -0
- package/dist/src/components/tag.jsx +126 -0
- package/dist/src/components/tag.jsx.map +1 -0
- package/dist/src/components/text/heading_content.d.ts +10 -0
- package/dist/src/components/text/heading_content.d.ts.map +1 -0
- package/dist/src/components/text/heading_content.jsx +31 -0
- package/dist/src/components/text/heading_content.jsx.map +1 -0
- package/dist/src/components/text/heading_marketing.d.ts +10 -0
- package/dist/src/components/text/heading_marketing.d.ts.map +1 -0
- package/dist/src/components/text/heading_marketing.jsx +31 -0
- package/dist/src/components/text/heading_marketing.jsx.map +1 -0
- package/dist/src/components/text/heading_shared.d.ts +10 -0
- package/dist/src/components/text/heading_shared.d.ts.map +1 -0
- package/dist/src/components/text/heading_shared.jsx +32 -0
- package/dist/src/components/text/heading_shared.jsx.map +1 -0
- package/dist/src/components/text/index.d.ts +12 -0
- package/dist/src/components/text/index.d.ts.map +1 -0
- package/dist/src/components/text/index.js +11 -0
- package/dist/src/components/text/index.js.map +1 -0
- package/dist/src/components/text/text_base.d.ts +13 -0
- package/dist/src/components/text/text_base.d.ts.map +1 -0
- package/dist/src/components/text/text_base.jsx +23 -0
- package/dist/src/components/text/text_base.jsx.map +1 -0
- package/dist/src/components/text/text_content.d.ts +11 -0
- package/dist/src/components/text/text_content.d.ts.map +1 -0
- package/dist/src/components/text/text_content.jsx +68 -0
- package/dist/src/components/text/text_content.jsx.map +1 -0
- package/dist/src/components/text/text_marketing.d.ts +11 -0
- package/dist/src/components/text/text_marketing.d.ts.map +1 -0
- package/dist/src/components/text/text_marketing.jsx +116 -0
- package/dist/src/components/text/text_marketing.jsx.map +1 -0
- package/dist/src/components/text/text_shared.d.ts +14 -0
- package/dist/src/components/text/text_shared.d.ts.map +1 -0
- package/dist/src/components/text/text_shared.jsx +55 -0
- package/dist/src/components/text/text_shared.jsx.map +1 -0
- package/dist/src/components/tile/horizontal_tile.d.ts +9 -0
- package/dist/src/components/tile/horizontal_tile.d.ts.map +1 -0
- package/dist/src/components/tile/horizontal_tile.jsx +43 -0
- package/dist/src/components/tile/horizontal_tile.jsx.map +1 -0
- package/dist/src/components/tile/index.d.ts +3 -0
- package/dist/src/components/tile/index.d.ts.map +1 -0
- package/dist/src/components/tile/index.js +3 -0
- package/dist/src/components/tile/index.js.map +1 -0
- package/dist/src/components/tile/shared.d.ts +17 -0
- package/dist/src/components/tile/shared.d.ts.map +1 -0
- package/dist/src/components/tile/shared.js +12 -0
- package/dist/src/components/tile/shared.js.map +1 -0
- package/dist/src/components/tile/vertical_tile.d.ts +10 -0
- package/dist/src/components/tile/vertical_tile.d.ts.map +1 -0
- package/dist/src/components/tile/vertical_tile.jsx +32 -0
- package/dist/src/components/tile/vertical_tile.jsx.map +1 -0
- package/dist/src/components/to_consolidate/card.d.ts +27 -0
- package/dist/src/components/to_consolidate/card.d.ts.map +1 -0
- package/dist/src/components/to_consolidate/card.jsx +93 -0
- package/dist/src/components/to_consolidate/card.jsx.map +1 -0
- package/dist/src/components/to_consolidate/index.d.ts +5 -0
- package/dist/src/components/to_consolidate/index.d.ts.map +1 -0
- package/dist/src/components/to_consolidate/index.js +5 -0
- package/dist/src/components/to_consolidate/index.js.map +1 -0
- package/dist/src/components/to_consolidate/markdown.d.ts +40 -0
- package/dist/src/components/to_consolidate/markdown.d.ts.map +1 -0
- package/dist/src/components/to_consolidate/markdown.jsx +454 -0
- package/dist/src/components/to_consolidate/markdown.jsx.map +1 -0
- package/dist/src/components/to_consolidate/pagination.d.ts +8 -0
- package/dist/src/components/to_consolidate/pagination.d.ts.map +1 -0
- package/dist/src/components/to_consolidate/pagination.jsx +88 -0
- package/dist/src/components/to_consolidate/pagination.jsx.map +1 -0
- package/dist/src/components/to_consolidate/tab_number_chip.d.ts +7 -0
- package/dist/src/components/to_consolidate/tab_number_chip.d.ts.map +1 -0
- package/dist/src/components/to_consolidate/tab_number_chip.jsx +22 -0
- package/dist/src/components/to_consolidate/tab_number_chip.jsx.map +1 -0
- package/dist/src/design_system/colors_theme.d.ts +213 -0
- package/dist/src/design_system/colors_theme.d.ts.map +1 -0
- package/dist/src/design_system/colors_theme.js +213 -0
- package/dist/src/design_system/colors_theme.js.map +1 -0
- package/dist/src/design_system/properties_theme.d.ts +175 -0
- package/dist/src/design_system/properties_theme.d.ts.map +1 -0
- package/dist/src/design_system/properties_theme.js +315 -0
- package/dist/src/design_system/properties_theme.js.map +1 -0
- package/dist/src/design_system/theme.d.ts +630 -0
- package/dist/src/design_system/theme.d.ts.map +1 -0
- package/dist/src/design_system/theme.js +17 -0
- package/dist/src/design_system/theme.js.map +1 -0
- package/dist/src/design_system/tokens/index.d.ts +6 -0
- package/dist/src/design_system/tokens/index.d.ts.map +1 -0
- package/dist/src/design_system/tokens/index.js +6 -0
- package/dist/src/design_system/tokens/index.js.map +1 -0
- package/dist/src/design_system/tokens/layouts.d.ts +29 -0
- package/dist/src/design_system/tokens/layouts.d.ts.map +1 -0
- package/dist/src/design_system/tokens/layouts.js +29 -0
- package/dist/src/design_system/tokens/layouts.js.map +1 -0
- package/dist/src/design_system/tokens/radiuses.d.ts +23 -0
- package/dist/src/design_system/tokens/radiuses.d.ts.map +1 -0
- package/dist/src/design_system/tokens/radiuses.js +23 -0
- package/dist/src/design_system/tokens/radiuses.js.map +1 -0
- package/dist/src/design_system/tokens/shadows.d.ts +23 -0
- package/dist/src/design_system/tokens/shadows.d.ts.map +1 -0
- package/dist/src/design_system/tokens/shadows.js +23 -0
- package/dist/src/design_system/tokens/shadows.js.map +1 -0
- package/dist/src/design_system/tokens/spaces.d.ts +15 -0
- package/dist/src/design_system/tokens/spaces.d.ts.map +1 -0
- package/dist/src/design_system/tokens/spaces.js +14 -0
- package/dist/src/design_system/tokens/spaces.js.map +1 -0
- package/dist/src/design_system/tokens/transitions.d.ts +20 -0
- package/dist/src/design_system/tokens/transitions.d.ts.map +1 -0
- package/dist/src/design_system/tokens/transitions.js +20 -0
- package/dist/src/design_system/tokens/transitions.js.map +1 -0
- package/dist/src/design_system/typography_theme.d.ts +189 -0
- package/dist/src/design_system/typography_theme.d.ts.map +1 -0
- package/dist/src/design_system/typography_theme.js +190 -0
- package/dist/src/design_system/typography_theme.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/type_utils.d.ts +6 -0
- package/dist/src/type_utils.d.ts.map +1 -0
- package/dist/src/type_utils.js +2 -0
- package/dist/src/type_utils.js.map +1 -0
- package/dist/src/ui_dependency_provider.d.ts +29 -0
- package/dist/src/ui_dependency_provider.d.ts.map +1 -0
- package/dist/src/ui_dependency_provider.jsx +14 -0
- package/dist/src/ui_dependency_provider.jsx.map +1 -0
- package/dist/src/utils/copy_to_clipboard.d.ts +7 -0
- package/dist/src/utils/copy_to_clipboard.d.ts.map +1 -0
- package/dist/src/utils/copy_to_clipboard.js +16 -0
- package/dist/src/utils/copy_to_clipboard.js.map +1 -0
- package/dist/src/utils/image_color.d.ts +7 -0
- package/dist/src/utils/image_color.d.ts.map +1 -0
- package/dist/src/utils/image_color.js +35 -0
- package/dist/src/utils/image_color.js.map +1 -0
- package/dist/src/utils/index.d.ts +4 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/sanitization.d.ts +11 -0
- package/dist/src/utils/sanitization.d.ts.map +1 -0
- package/dist/src/utils/sanitization.js +16 -0
- package/dist/src/utils/sanitization.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +71 -0
- package/src/codemods/generate_color_property_tokens.mjs +97 -0
- package/src/codemods/generate_color_theme_files.mjs +46 -0
- package/src/codemods/generate_typograpy_tokens_files.mjs +136 -0
- package/src/components/action_link.tsx +59 -0
- package/src/components/actor_template_card.tsx +99 -0
- package/src/components/badge.tsx +144 -0
- package/src/components/banner.tsx +95 -0
- package/src/components/blog_article.tsx +85 -0
- package/src/components/box.tsx +127 -0
- package/src/components/button.tsx +303 -0
- package/src/components/chip.tsx +121 -0
- package/src/components/code/action_button.tsx +96 -0
- package/src/components/code/code_block/code_block.styled.tsx +228 -0
- package/src/components/code/code_block/code_block.tsx +235 -0
- package/src/components/code/code_block/utils.ts +19 -0
- package/src/components/code/index.ts +3 -0
- package/src/components/code/inline_code/inline_code.tsx +44 -0
- package/src/components/code/one_line_code/one_line_code.tsx +232 -0
- package/src/components/code/syntax_highlighter.tsx +125 -0
- package/src/components/color_wheel_gradient.tsx +31 -0
- package/src/components/floating/index.ts +3 -0
- package/src/components/floating/menu.tsx +191 -0
- package/src/components/floating/menu_common.tsx +31 -0
- package/src/components/floating/menu_components.tsx +94 -0
- package/src/components/image.tsx +23 -0
- package/src/components/index.ts +20 -0
- package/src/components/link.tsx +114 -0
- package/src/components/message.tsx +157 -0
- package/src/components/readme_renderer/index.ts +3 -0
- package/src/components/readme_renderer/pythonize_value.ts +78 -0
- package/src/components/readme_renderer/table_of_contents.tsx +257 -0
- package/src/components/readme_renderer/utils.tsx +46 -0
- package/src/components/simple_markdown/index.tsx +2 -0
- package/src/components/simple_markdown/simple_markdown.tsx +181 -0
- package/src/components/simple_markdown/simple_markdown_components.tsx +295 -0
- package/src/components/tag.tsx +185 -0
- package/src/components/text/heading_content.tsx +56 -0
- package/src/components/text/heading_marketing.tsx +55 -0
- package/src/components/text/heading_shared.tsx +57 -0
- package/src/components/text/index.ts +18 -0
- package/src/components/text/text_base.tsx +52 -0
- package/src/components/text/text_content.tsx +104 -0
- package/src/components/text/text_marketing.tsx +152 -0
- package/src/components/text/text_shared.tsx +96 -0
- package/src/components/tile/horizontal_tile.tsx +76 -0
- package/src/components/tile/index.ts +2 -0
- package/src/components/tile/shared.ts +27 -0
- package/src/components/tile/vertical_tile.tsx +58 -0
- package/src/components/to_consolidate/card.tsx +141 -0
- package/src/components/to_consolidate/index.ts +4 -0
- package/src/components/to_consolidate/markdown.tsx +593 -0
- package/src/components/to_consolidate/pagination.tsx +139 -0
- package/src/components/to_consolidate/tab_number_chip.tsx +31 -0
- package/src/design_system/colors_theme.ts +213 -0
- package/src/design_system/generate_color_definitions.js +43 -0
- package/src/design_system/properties_theme.ts +453 -0
- package/src/design_system/supernova_color_tokens.json +1766 -0
- package/src/design_system/supernova_typography_tokens.json +657 -0
- package/src/design_system/theme.ts +26 -0
- package/src/design_system/tokens/index.ts +5 -0
- package/src/design_system/tokens/layouts.ts +29 -0
- package/src/design_system/tokens/radiuses.ts +22 -0
- package/src/design_system/tokens/shadows.ts +22 -0
- package/src/design_system/tokens/spaces.ts +15 -0
- package/src/design_system/tokens/transitions.ts +19 -0
- package/src/design_system/typography_theme.ts +197 -0
- package/src/index.ts +7 -0
- package/src/type_utils.ts +7 -0
- package/src/ui_dependency_provider.tsx +50 -0
- package/src/utils/copy_to_clipboard.ts +24 -0
- package/src/utils/image_color.ts +44 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/sanitization.ts +14 -0
- package/tsconfig.build.json +18 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { theme } from '../../../design_system/theme';
|
|
5
|
+
import type { RegularBoxProps } from '../../box';
|
|
6
|
+
import { Text } from '../../text';
|
|
7
|
+
import type { SharedTextSize } from '../../text/text_shared';
|
|
8
|
+
|
|
9
|
+
// TODO: We should not need to export these once we consolidate Markdown
|
|
10
|
+
export const inlineCodeStyles = css`
|
|
11
|
+
width: fit-content;
|
|
12
|
+
padding: ${theme.space.space2} 0.6rem;
|
|
13
|
+
background-color: ${theme.color.neutral.backgroundMuted};
|
|
14
|
+
border-radius: ${theme.radius.radius8};
|
|
15
|
+
border: 1px solid ${theme.color.neutral.border};
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
const Wrapper = styled.span`
|
|
19
|
+
code {
|
|
20
|
+
${inlineCodeStyles}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
type InlineCodeProps = RegularBoxProps & {
|
|
25
|
+
children: React.ReactNode,
|
|
26
|
+
size?: SharedTextSize,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// This might be just a Chip component
|
|
30
|
+
export const InlineCode: React.FC<InlineCodeProps> = ({
|
|
31
|
+
children,
|
|
32
|
+
size,
|
|
33
|
+
...props
|
|
34
|
+
}) => (
|
|
35
|
+
<Wrapper {...props}>
|
|
36
|
+
<Text
|
|
37
|
+
type="code"
|
|
38
|
+
as="code"
|
|
39
|
+
size={size}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</Text>
|
|
43
|
+
</Wrapper>
|
|
44
|
+
);
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { Eye16, EyeOff16 } from '@apify/icons';
|
|
5
|
+
|
|
6
|
+
import { theme } from '../../../design_system/theme';
|
|
7
|
+
import type { BoxProps } from '../../box';
|
|
8
|
+
import { Text } from '../../text';
|
|
9
|
+
import type { SharedTextSize } from '../../text/text_shared';
|
|
10
|
+
import { ActionButton, CopyButton } from '../action_button';
|
|
11
|
+
import SyntaxHighlighter, { SyntaxHighlighterBaseStylesWrapper } from '../syntax_highlighter';
|
|
12
|
+
import type { SyntaxHighlighterBaseStylesWrapperProps } from '../syntax_highlighter';
|
|
13
|
+
|
|
14
|
+
export const oneLineCodeClassNames = {
|
|
15
|
+
gradientWrapper: 'OneLineCode-GradientWrapper',
|
|
16
|
+
scrollableWrapper: 'OneLineCode-ScrollableWrapper',
|
|
17
|
+
methodChip: 'OneLineCode-MethodChip',
|
|
18
|
+
gradient: 'OneLineCode-Gradient',
|
|
19
|
+
buttons: 'OneLineCode-Buttons',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'PATCH';
|
|
23
|
+
type ThemeType = keyof Pick<
|
|
24
|
+
(typeof theme)['color'],
|
|
25
|
+
'primary' | 'success' | 'warning' | 'danger' | 'neutral'
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
const HTML_METHOD_CHIP_STYLES: Record<HttpMethod, ThemeType> = {
|
|
29
|
+
GET: 'primary',
|
|
30
|
+
POST: 'success',
|
|
31
|
+
PUT: 'warning',
|
|
32
|
+
DELETE: 'danger',
|
|
33
|
+
HEAD: 'neutral',
|
|
34
|
+
PATCH: 'neutral',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function getChipStyles(httpMethod: HttpMethod) {
|
|
38
|
+
const styles = theme.color[HTML_METHOD_CHIP_STYLES[httpMethod]];
|
|
39
|
+
return css`
|
|
40
|
+
background-color: ${styles.chipBackground};
|
|
41
|
+
color: ${'chipText' in styles ? styles.chipText : styles.text};
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type OneLineCodeWrapperProps = SyntaxHighlighterBaseStylesWrapperProps & {
|
|
46
|
+
$httpMethod?: HttpMethod;
|
|
47
|
+
$fitContent?: boolean;
|
|
48
|
+
$showBashPrefixes?: boolean;
|
|
49
|
+
$disabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const OneLineCodeWrapper = styled(SyntaxHighlighterBaseStylesWrapper)<OneLineCodeWrapperProps>`
|
|
53
|
+
display: flex;
|
|
54
|
+
padding-right: ${theme.space.space16} !important;
|
|
55
|
+
${({ $fitContent }) => $fitContent && css`
|
|
56
|
+
width: fit-content;
|
|
57
|
+
`}
|
|
58
|
+
|
|
59
|
+
${({ $disabled }) => $disabled && css`
|
|
60
|
+
opacity: 0.5;
|
|
61
|
+
cursor: not-allowed;
|
|
62
|
+
`}
|
|
63
|
+
|
|
64
|
+
height: 4.6rem;
|
|
65
|
+
|
|
66
|
+
.${oneLineCodeClassNames.buttons} {
|
|
67
|
+
display: flex;
|
|
68
|
+
align-items: center;
|
|
69
|
+
gap: ${theme.space.space8};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.${oneLineCodeClassNames.methodChip} {
|
|
73
|
+
padding: 0 ${theme.space.space4};
|
|
74
|
+
margin-top: ${theme.space.space2};
|
|
75
|
+
border-radius: ${theme.radius.radius6};
|
|
76
|
+
height: 2.4rem;
|
|
77
|
+
${({ $httpMethod }) => $httpMethod && getChipStyles($httpMethod)}
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.${oneLineCodeClassNames.gradientWrapper} {
|
|
83
|
+
position: relative;
|
|
84
|
+
flex: 1;
|
|
85
|
+
min-width: 0;
|
|
86
|
+
padding-top: ${theme.space.space8};
|
|
87
|
+
display: flex;
|
|
88
|
+
|
|
89
|
+
.${oneLineCodeClassNames.gradient} {
|
|
90
|
+
position: absolute;
|
|
91
|
+
right: 0;
|
|
92
|
+
top: 0;
|
|
93
|
+
bottom: 0;
|
|
94
|
+
width: 4rem;
|
|
95
|
+
background: linear-gradient(
|
|
96
|
+
to right,
|
|
97
|
+
transparent,
|
|
98
|
+
${theme.color.neutral.backgroundMuted} 3rem
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.${oneLineCodeClassNames.scrollableWrapper} {
|
|
104
|
+
flex: 1;
|
|
105
|
+
overflow-x: auto;
|
|
106
|
+
overflow-y: hidden;
|
|
107
|
+
display: flex;
|
|
108
|
+
gap: ${theme.space.space16};
|
|
109
|
+
padding: 0 ${theme.space.space8} !important;
|
|
110
|
+
margin-left: ${theme.space.space8} !important;
|
|
111
|
+
height: 100%;
|
|
112
|
+
|
|
113
|
+
scrollbar-width: thin;
|
|
114
|
+
scrollbar-color: ${theme.color.neutral.border} transparent;
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
.CodePre {
|
|
118
|
+
overflow: unset !important;
|
|
119
|
+
display: flex;
|
|
120
|
+
flex: 1;
|
|
121
|
+
align-items: center;
|
|
122
|
+
height: 2.8rem;
|
|
123
|
+
|
|
124
|
+
code {
|
|
125
|
+
& > span {
|
|
126
|
+
text-overflow: ellipsis;
|
|
127
|
+
overflow: hidden;
|
|
128
|
+
white-space: nowrap;
|
|
129
|
+
vertical-align: text-top;
|
|
130
|
+
${({ $showBashPrefixes }) => $showBashPrefixes && css`
|
|
131
|
+
&::before {
|
|
132
|
+
color: ${theme.color.lavender.base};
|
|
133
|
+
padding-right: ${theme.space.space16};
|
|
134
|
+
min-width: ${theme.space.space24};
|
|
135
|
+
user-select: none;
|
|
136
|
+
-webkit-user-select: none;
|
|
137
|
+
content: "$";
|
|
138
|
+
font-size: 1em;
|
|
139
|
+
}
|
|
140
|
+
`}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
export type OneLineCodeProps = BoxProps & {
|
|
148
|
+
children: string;
|
|
149
|
+
language?: string;
|
|
150
|
+
size?: SharedTextSize;
|
|
151
|
+
httpMethod?: HttpMethod;
|
|
152
|
+
actionButtonLabel?: string;
|
|
153
|
+
onActionButtonClick?: () => Promise<void> | void;
|
|
154
|
+
fullWidth?: boolean;
|
|
155
|
+
secretPlaceholder?: string;
|
|
156
|
+
secret?: string;
|
|
157
|
+
disabled?: boolean;
|
|
158
|
+
hideCopyButton?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function OneLineCode({
|
|
162
|
+
children,
|
|
163
|
+
language,
|
|
164
|
+
size,
|
|
165
|
+
httpMethod,
|
|
166
|
+
actionButtonLabel,
|
|
167
|
+
onActionButtonClick,
|
|
168
|
+
fullWidth,
|
|
169
|
+
secretPlaceholder = '***',
|
|
170
|
+
secret,
|
|
171
|
+
disabled,
|
|
172
|
+
hideCopyButton,
|
|
173
|
+
...rest
|
|
174
|
+
}: OneLineCodeProps) {
|
|
175
|
+
const hasSecret = secret !== undefined;
|
|
176
|
+
const [showSecret, setShowSecret] = useState(false);
|
|
177
|
+
const codeWithSecret = useMemo(() => {
|
|
178
|
+
if (!hasSecret) return children;
|
|
179
|
+
return children.replace(secretPlaceholder, secret);
|
|
180
|
+
}, [children, secret, hasSecret, secretPlaceholder]);
|
|
181
|
+
const code = showSecret ? codeWithSecret : children;
|
|
182
|
+
|
|
183
|
+
const showBashPrefixes = language === 'bash';
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<OneLineCodeWrapper
|
|
187
|
+
$httpMethod={httpMethod}
|
|
188
|
+
$fullWidth={fullWidth}
|
|
189
|
+
$showBashPrefixes={showBashPrefixes}
|
|
190
|
+
$disabled={disabled}
|
|
191
|
+
{...rest}
|
|
192
|
+
>
|
|
193
|
+
<div className={oneLineCodeClassNames.gradientWrapper}>
|
|
194
|
+
<div className={oneLineCodeClassNames.scrollableWrapper}>
|
|
195
|
+
{httpMethod && (
|
|
196
|
+
<Text className={oneLineCodeClassNames.methodChip} as='div'>
|
|
197
|
+
{httpMethod}
|
|
198
|
+
</Text>
|
|
199
|
+
)}
|
|
200
|
+
<SyntaxHighlighter
|
|
201
|
+
language={language}
|
|
202
|
+
size={size}
|
|
203
|
+
wrapLines
|
|
204
|
+
>
|
|
205
|
+
{code}
|
|
206
|
+
</SyntaxHighlighter>
|
|
207
|
+
</div>
|
|
208
|
+
<div className={oneLineCodeClassNames.gradient} />
|
|
209
|
+
</div>
|
|
210
|
+
<div className={oneLineCodeClassNames.buttons}>
|
|
211
|
+
{hasSecret && (
|
|
212
|
+
<ActionButton
|
|
213
|
+
onClick={() => setShowSecret((prev) => !prev)}
|
|
214
|
+
data-test='toggle-visibility-button'
|
|
215
|
+
>
|
|
216
|
+
{showSecret ? (
|
|
217
|
+
<EyeOff16 viewBox="0 0 16 16" />
|
|
218
|
+
) : (
|
|
219
|
+
<Eye16 viewBox="0 0 16 16" />
|
|
220
|
+
)}
|
|
221
|
+
</ActionButton>
|
|
222
|
+
)}
|
|
223
|
+
{!hideCopyButton && <CopyButton code={codeWithSecret} />}
|
|
224
|
+
{!!onActionButtonClick && (
|
|
225
|
+
<ActionButton onClick={onActionButtonClick}>
|
|
226
|
+
{actionButtonLabel}
|
|
227
|
+
</ActionButton>
|
|
228
|
+
)}
|
|
229
|
+
</div>
|
|
230
|
+
</OneLineCodeWrapper >
|
|
231
|
+
);
|
|
232
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
// https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/228
|
|
3
|
+
import type { SyntaxHighlighterProps as ReactSyntaxHighlighterProps } from 'react-syntax-highlighter';
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
+
// @ts-ignore The library is badly typed and does not export the type
|
|
6
|
+
import bash from 'react-syntax-highlighter/dist/esm/languages/prism/bash';
|
|
7
|
+
import dockerFile from 'react-syntax-highlighter/dist/esm/languages/prism/docker';
|
|
8
|
+
import http from 'react-syntax-highlighter/dist/esm/languages/prism/http';
|
|
9
|
+
import js from 'react-syntax-highlighter/dist/esm/languages/prism/javascript';
|
|
10
|
+
import json from 'react-syntax-highlighter/dist/esm/languages/prism/json';
|
|
11
|
+
import html from 'react-syntax-highlighter/dist/esm/languages/prism/markup';
|
|
12
|
+
import python from 'react-syntax-highlighter/dist/esm/languages/prism/python';
|
|
13
|
+
import ts from 'react-syntax-highlighter/dist/esm/languages/prism/typescript';
|
|
14
|
+
import xml from 'react-syntax-highlighter/dist/esm/languages/prism/xml-doc';
|
|
15
|
+
import yaml from 'react-syntax-highlighter/dist/esm/languages/prism/yaml';
|
|
16
|
+
import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light';
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
+
// @ts-ignore The library is badly typed and does not export the type
|
|
19
|
+
import dark from 'react-syntax-highlighter/dist/esm/styles/prism/night-owl';
|
|
20
|
+
import light from 'react-syntax-highlighter/dist/esm/styles/prism/prism';
|
|
21
|
+
import styled, { css } from 'styled-components';
|
|
22
|
+
|
|
23
|
+
import { theme } from '../../design_system/theme';
|
|
24
|
+
import { useSharedUiDependencies } from '../../ui_dependency_provider';
|
|
25
|
+
import { Box } from '../box';
|
|
26
|
+
import { Text, type SharedTextProps } from '../text';
|
|
27
|
+
import type { SharedTextSize } from '../text/text_shared';
|
|
28
|
+
|
|
29
|
+
ReactSyntaxHighlighter.registerLanguage('typescript', ts);
|
|
30
|
+
ReactSyntaxHighlighter.registerLanguage('javascript', js);
|
|
31
|
+
ReactSyntaxHighlighter.registerLanguage('json', json);
|
|
32
|
+
ReactSyntaxHighlighter.registerLanguage('bash', bash);
|
|
33
|
+
ReactSyntaxHighlighter.registerLanguage('docker', dockerFile);
|
|
34
|
+
ReactSyntaxHighlighter.registerLanguage('html', html);
|
|
35
|
+
ReactSyntaxHighlighter.registerLanguage('xml', xml);
|
|
36
|
+
ReactSyntaxHighlighter.registerLanguage('yaml', yaml);
|
|
37
|
+
ReactSyntaxHighlighter.registerLanguage('python', python);
|
|
38
|
+
ReactSyntaxHighlighter.registerLanguage('http', http);
|
|
39
|
+
ReactSyntaxHighlighter.registerLanguage('jsonp', json);
|
|
40
|
+
ReactSyntaxHighlighter.registerLanguage('jsonl', json);
|
|
41
|
+
ReactSyntaxHighlighter.registerLanguage('rss', xml);
|
|
42
|
+
|
|
43
|
+
const StyledPre = styled(Text)`
|
|
44
|
+
width: 100%;
|
|
45
|
+
position: relative;
|
|
46
|
+
|
|
47
|
+
*,
|
|
48
|
+
*::before,
|
|
49
|
+
*::after {
|
|
50
|
+
text-shadow: none !important;
|
|
51
|
+
font-style: normal !important;
|
|
52
|
+
font-family: inherit !important;
|
|
53
|
+
font-size: inherit !important;
|
|
54
|
+
font-weight: inherit !important;
|
|
55
|
+
line-height: inherit !important;
|
|
56
|
+
background-color: transparent !important;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
code {
|
|
60
|
+
min-width: 100%;
|
|
61
|
+
display: inline-block;
|
|
62
|
+
vertical-align: middle;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
// Syntax highlighter uses inline style a lot which makes it hard to override them. To do so, we make the library not
|
|
68
|
+
// use styles that we wish to set on our own (font-based styles, spacing, background, ...),
|
|
69
|
+
const inlineCssReset = {
|
|
70
|
+
fontFamily: undefined,
|
|
71
|
+
fontSize: undefined,
|
|
72
|
+
fontWeight: undefined,
|
|
73
|
+
lineHeight: undefined,
|
|
74
|
+
background: undefined,
|
|
75
|
+
margin: undefined,
|
|
76
|
+
padding: undefined,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type SyntaxHighlighterProps = ReactSyntaxHighlighterProps & { size: SharedTextSize };
|
|
80
|
+
|
|
81
|
+
export const SyntaxHighlighter = forwardRef<HTMLPreElement, SyntaxHighlighterProps>(({
|
|
82
|
+
size,
|
|
83
|
+
children,
|
|
84
|
+
...rest
|
|
85
|
+
}, ref) => {
|
|
86
|
+
const { uiTheme } = useSharedUiDependencies();
|
|
87
|
+
|
|
88
|
+
const PreTag = (preProps: any) => {
|
|
89
|
+
return <StyledPre {...preProps} size={size} forwardedAs='pre' type='code' ref={ref}/>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ReactSyntaxHighlighter
|
|
94
|
+
PreTag={PreTag}
|
|
95
|
+
customStyle={inlineCssReset}
|
|
96
|
+
className="CodePre"
|
|
97
|
+
style={uiTheme === 'DARK' ? dark : light}
|
|
98
|
+
{...rest}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</ReactSyntaxHighlighter>
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export type SyntaxHighlighterBaseStylesWrapperProps = SharedTextProps & {
|
|
106
|
+
$fullWidth?: boolean;
|
|
107
|
+
$fullHeight?: boolean;
|
|
108
|
+
$showLineNumbers?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const SyntaxHighlighterBaseStylesWrapper = styled(Box)<SyntaxHighlighterBaseStylesWrapperProps>`
|
|
112
|
+
background-color: ${theme.color.neutral.backgroundMuted} !important;
|
|
113
|
+
border: 1px solid ${theme.color.neutral.border};
|
|
114
|
+
border-radius: ${theme.radius.radius12};
|
|
115
|
+
overflow: hidden;
|
|
116
|
+
|
|
117
|
+
width: 100%;
|
|
118
|
+
${({ $fullWidth }) => !$fullWidth && css`max-width: 860px;`}
|
|
119
|
+
${({ $fullHeight }) => !$fullHeight && css`max-height: 600px;`}
|
|
120
|
+
|
|
121
|
+
background-color: transparent;
|
|
122
|
+
position: relative;
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
export default SyntaxHighlighter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export interface ColorWheelGradientProps {
|
|
4
|
+
translateX?: number,
|
|
5
|
+
translateY?: number,
|
|
6
|
+
rotation?: number,
|
|
7
|
+
radius?: number,
|
|
8
|
+
blurSize?: number,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const ColorWheelGradient = styled.div<ColorWheelGradientProps>`${({ radius, rotation = 0, blurSize = 40, translateX = 0, translateY = 0 }) => `
|
|
12
|
+
z-index: 1;
|
|
13
|
+
position: absolute;
|
|
14
|
+
width: ${radius ? `${radius}px` : 'auto'};
|
|
15
|
+
height: ${radius ? `${radius}px` : 'auto'};
|
|
16
|
+
transform-origin: center;
|
|
17
|
+
transform: translate(${translateX}px, ${translateY}px) rotate(${rotation}deg);
|
|
18
|
+
|
|
19
|
+
opacity: 0.30;
|
|
20
|
+
background: conic-gradient(
|
|
21
|
+
rgba(93, 133, 225, 0.99) 0deg,
|
|
22
|
+
rgba(106, 20, 222, 0.99) 69deg,
|
|
23
|
+
rgba(228, 68, 103, 0.99) 150deg,
|
|
24
|
+
rgba(250, 129, 54, 0.99) 221deg,
|
|
25
|
+
rgba(240, 178, 27, 0.99) 287deg,
|
|
26
|
+
rgba(18, 150, 111, 0.99) 360deg
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
border-radius: 50%;
|
|
30
|
+
filter: blur(${blurSize}px)
|
|
31
|
+
`}`;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useRole,
|
|
3
|
+
useListNavigation,
|
|
4
|
+
useTypeahead,
|
|
5
|
+
useClick,
|
|
6
|
+
useDismiss,
|
|
7
|
+
useInteractions,
|
|
8
|
+
FloatingPortal,
|
|
9
|
+
FloatingFocusManager,
|
|
10
|
+
} from '@floating-ui/react';
|
|
11
|
+
import clsx from 'clsx';
|
|
12
|
+
import React, {
|
|
13
|
+
useState,
|
|
14
|
+
useRef,
|
|
15
|
+
useMemo,
|
|
16
|
+
} from 'react';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
Box,
|
|
20
|
+
type BoxProps,
|
|
21
|
+
} from '../box';
|
|
22
|
+
import { Text } from '../text';
|
|
23
|
+
import { useFloatingMenu } from './menu_common';
|
|
24
|
+
import {
|
|
25
|
+
DropdownMenuBaseComponent,
|
|
26
|
+
ListMenuComponent,
|
|
27
|
+
ListMenuItemComponent,
|
|
28
|
+
} from './menu_components';
|
|
29
|
+
|
|
30
|
+
export const menuClassNames = {
|
|
31
|
+
WRAPPER: 'menu-wrapper',
|
|
32
|
+
BASE: 'menu-base',
|
|
33
|
+
LIST: 'menu-list',
|
|
34
|
+
ITEM: 'menu-item',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type SelectActionType = 'click' | 'enter' | 'space' | 'type';
|
|
38
|
+
|
|
39
|
+
// It might be tempting to define label as ReactNode, but we need to have the string value for keyboard navigation
|
|
40
|
+
// More difficult cases can be handled using renderOption prop
|
|
41
|
+
export interface MenuOption {
|
|
42
|
+
label: string,
|
|
43
|
+
value: string,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface MenuProps<T = MenuOption> {
|
|
47
|
+
options: T[],
|
|
48
|
+
value?: string,
|
|
49
|
+
onSelect: (newValue: string, selectedBy: SelectActionType) => void,
|
|
50
|
+
defaultLabel?: React.ReactNode,
|
|
51
|
+
closeOnSelect?: boolean,
|
|
52
|
+
renderOption?: (option: T) => React.ReactNode,
|
|
53
|
+
components?: {
|
|
54
|
+
MenuBase?: React.ElementType,
|
|
55
|
+
Menu?: React.ElementType,
|
|
56
|
+
MenuItem?: React.ElementType,
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const defaultRenderOption = ({ label }: MenuOption) => (<Text as='span'>{label}</Text>);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This example is a Select taken from https://floating-ui.com/docs/react-examples
|
|
64
|
+
* It tries to mimic API of react-select as closely as possible
|
|
65
|
+
*/
|
|
66
|
+
export const Menu = <T extends MenuOption>({
|
|
67
|
+
options,
|
|
68
|
+
value,
|
|
69
|
+
onSelect,
|
|
70
|
+
closeOnSelect = true,
|
|
71
|
+
defaultLabel,
|
|
72
|
+
components,
|
|
73
|
+
renderOption,
|
|
74
|
+
className,
|
|
75
|
+
...rest
|
|
76
|
+
}: MenuProps<T> & BoxProps) => {
|
|
77
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
78
|
+
const { refs, floatingStyles, context } = useFloatingMenu({
|
|
79
|
+
isOpen,
|
|
80
|
+
setIsOpen,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const selectedIndex = useMemo(() => {
|
|
84
|
+
const foundIndex = options.findIndex((option) => option.value === value);
|
|
85
|
+
return foundIndex < 0 ? null : foundIndex;
|
|
86
|
+
}, [options, value]);
|
|
87
|
+
|
|
88
|
+
const [activeIndex, setActiveIndex] = useState<number | null>(null);
|
|
89
|
+
const handleSelect = (newIndex: number, selectedBy: SelectActionType) => {
|
|
90
|
+
onSelect(options[newIndex].value, selectedBy);
|
|
91
|
+
if (closeOnSelect) setIsOpen(false);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const listRef = useRef<Array<HTMLElement | null>>([]);
|
|
95
|
+
const isTypingRef = useRef(false);
|
|
96
|
+
const listContentRef = useRef(options.map((option) => option.label));
|
|
97
|
+
|
|
98
|
+
const click = useClick(context, { event: 'mousedown' });
|
|
99
|
+
const dismiss = useDismiss(context);
|
|
100
|
+
const typeahead = useTypeahead(context, {
|
|
101
|
+
listRef: listContentRef,
|
|
102
|
+
activeIndex,
|
|
103
|
+
selectedIndex,
|
|
104
|
+
onMatch: isOpen ? setActiveIndex : (newIndex) => onSelect(options[newIndex].value, 'type'),
|
|
105
|
+
onTypingChange(isTyping) {
|
|
106
|
+
isTypingRef.current = isTyping;
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const role = useRole(context, { role: 'listbox' });
|
|
110
|
+
const listNav = useListNavigation(context, {
|
|
111
|
+
listRef,
|
|
112
|
+
activeIndex,
|
|
113
|
+
selectedIndex,
|
|
114
|
+
onNavigate: setActiveIndex,
|
|
115
|
+
loop: true,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const { getFloatingProps, getItemProps, getReferenceProps } = useInteractions([click, dismiss, role, listNav, typeahead]);
|
|
119
|
+
|
|
120
|
+
const MenuBaseComponent = components?.MenuBase || DropdownMenuBaseComponent;
|
|
121
|
+
const MenuComponent = components?.Menu || ListMenuComponent;
|
|
122
|
+
const MenuItemComponent = components?.MenuItem || ListMenuItemComponent;
|
|
123
|
+
|
|
124
|
+
const effectiveRenderOption = renderOption || defaultRenderOption;
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<Box
|
|
128
|
+
className={clsx(className, menuClassNames.WRAPPER)}
|
|
129
|
+
{...rest}
|
|
130
|
+
>
|
|
131
|
+
<MenuBaseComponent
|
|
132
|
+
aria-labelledby="select-label"
|
|
133
|
+
aria-autocomplete="none"
|
|
134
|
+
ref={refs.setReference}
|
|
135
|
+
{...getReferenceProps()}
|
|
136
|
+
className={menuClassNames.BASE}
|
|
137
|
+
tabindex="0"
|
|
138
|
+
>
|
|
139
|
+
{selectedIndex !== null ? options[selectedIndex].label : defaultLabel}
|
|
140
|
+
</MenuBaseComponent>
|
|
141
|
+
<FloatingPortal>
|
|
142
|
+
<FloatingFocusManager
|
|
143
|
+
context={context}
|
|
144
|
+
modal={false}
|
|
145
|
+
>
|
|
146
|
+
<MenuComponent
|
|
147
|
+
ref={refs.setFloating}
|
|
148
|
+
style={{
|
|
149
|
+
...floatingStyles,
|
|
150
|
+
// TODO: We should consider not doing this by default
|
|
151
|
+
...!isOpen && { display: 'none' }, // needs to be rendered, because of SEO
|
|
152
|
+
}}
|
|
153
|
+
{...getFloatingProps()}
|
|
154
|
+
className={menuClassNames.LIST}
|
|
155
|
+
>
|
|
156
|
+
{options.map((option, i) => (
|
|
157
|
+
<MenuItemComponent
|
|
158
|
+
key={option.value}
|
|
159
|
+
$isSelected={i === selectedIndex}
|
|
160
|
+
$isActive={i === activeIndex}
|
|
161
|
+
ref={(node: HTMLElement | null) => {
|
|
162
|
+
listRef.current[i] = node;
|
|
163
|
+
}}
|
|
164
|
+
role="option"
|
|
165
|
+
tabIndex={i === activeIndex ? 0 : -1}
|
|
166
|
+
className={menuClassNames.ITEM}
|
|
167
|
+
aria-selected={i === selectedIndex && i === activeIndex}
|
|
168
|
+
{...getItemProps({
|
|
169
|
+
onClick: () => handleSelect(i, 'click'), // Handles mouse click
|
|
170
|
+
onKeyDown: (event) => {
|
|
171
|
+
if (event.key === 'Enter') {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
handleSelect(i, 'enter'); // Handles enter press
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (event.key === ' ' && !isTypingRef.current) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
handleSelect(i, 'space');
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
})}
|
|
182
|
+
>
|
|
183
|
+
{effectiveRenderOption(option)}
|
|
184
|
+
</MenuItemComponent>
|
|
185
|
+
))}
|
|
186
|
+
</MenuComponent>
|
|
187
|
+
</FloatingFocusManager>
|
|
188
|
+
</FloatingPortal>
|
|
189
|
+
</Box>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useFloating,
|
|
3
|
+
offset,
|
|
4
|
+
size,
|
|
5
|
+
autoUpdate,
|
|
6
|
+
} from '@floating-ui/react';
|
|
7
|
+
|
|
8
|
+
export const useFloatingMenu = ({
|
|
9
|
+
isOpen,
|
|
10
|
+
setIsOpen,
|
|
11
|
+
}: {
|
|
12
|
+
isOpen: boolean,
|
|
13
|
+
setIsOpen: (newIsOpen: boolean) => void
|
|
14
|
+
}) => useFloating<Element>({
|
|
15
|
+
placement: 'bottom-start',
|
|
16
|
+
open: isOpen,
|
|
17
|
+
onOpenChange: setIsOpen,
|
|
18
|
+
whileElementsMounted: autoUpdate,
|
|
19
|
+
middleware: [
|
|
20
|
+
offset(5),
|
|
21
|
+
size({
|
|
22
|
+
apply({ elements, availableHeight }) {
|
|
23
|
+
Object.assign(elements.floating.style, {
|
|
24
|
+
maxHeight: `${availableHeight}px`,
|
|
25
|
+
minHeight: '50px',
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
padding: 10,
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
});
|