@apify/ui-library 1.92.1-featimprovetooltip-7e1224.86 → 1.93.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.
Files changed (38) hide show
  1. package/dist/src/components/floating/index.d.ts +0 -2
  2. package/dist/src/components/floating/index.d.ts.map +1 -1
  3. package/dist/src/components/floating/index.js +0 -2
  4. package/dist/src/components/floating/index.js.map +1 -1
  5. package/dist/src/components/index.d.ts +0 -1
  6. package/dist/src/components/index.d.ts.map +1 -1
  7. package/dist/src/components/index.js +0 -1
  8. package/dist/src/components/index.js.map +1 -1
  9. package/dist/src/components/simple_markdown/simple_markdown.d.ts.map +1 -1
  10. package/dist/src/components/simple_markdown/simple_markdown.js +8 -0
  11. package/dist/src/components/simple_markdown/simple_markdown.js.map +1 -1
  12. package/dist/tsconfig.build.tsbuildinfo +1 -1
  13. package/package.json +2 -2
  14. package/src/components/floating/index.ts +0 -2
  15. package/src/components/index.ts +0 -1
  16. package/src/components/simple_markdown/simple_markdown.tsx +25 -0
  17. package/dist/src/components/floating/floating_component_base.d.ts +0 -40
  18. package/dist/src/components/floating/floating_component_base.d.ts.map +0 -1
  19. package/dist/src/components/floating/floating_component_base.js +0 -109
  20. package/dist/src/components/floating/floating_component_base.js.map +0 -1
  21. package/dist/src/components/floating/tooltip.d.ts +0 -41
  22. package/dist/src/components/floating/tooltip.d.ts.map +0 -1
  23. package/dist/src/components/floating/tooltip.js +0 -66
  24. package/dist/src/components/floating/tooltip.js.map +0 -1
  25. package/dist/src/components/floating/tooltip_content.d.ts +0 -5
  26. package/dist/src/components/floating/tooltip_content.d.ts.map +0 -1
  27. package/dist/src/components/floating/tooltip_content.js +0 -65
  28. package/dist/src/components/floating/tooltip_content.js.map +0 -1
  29. package/dist/src/components/shortcut.d.ts +0 -9
  30. package/dist/src/components/shortcut.d.ts.map +0 -1
  31. package/dist/src/components/shortcut.js +0 -29
  32. package/dist/src/components/shortcut.js.map +0 -1
  33. package/src/components/floating/floating_component_base.tsx +0 -199
  34. package/src/components/floating/tooltip.stories.jsx +0 -130
  35. package/src/components/floating/tooltip.tsx +0 -146
  36. package/src/components/floating/tooltip_content.tsx +0 -103
  37. package/src/components/shortcut.stories.jsx +0 -58
  38. package/src/components/shortcut.tsx +0 -55
@@ -1,199 +0,0 @@
1
- import {
2
- autoPlacement,
3
- autoUpdate,
4
- flip,
5
- FloatingPortal,
6
- hide,
7
- offset,
8
- shift,
9
- type Strategy,
10
- useFloating,
11
- useTransitionStyles,
12
- } from '@floating-ui/react';
13
- import clsx from 'clsx';
14
- import { type ComponentType, type CSSProperties, forwardRef, type MouseEvent, type ReactNode, type RefObject } from 'react';
15
- import styled from 'styled-components';
16
-
17
- import { theme } from '../../design_system/theme.js';
18
-
19
- export const classNames = {
20
- CHILDREN: 'FloatingComponent-children',
21
- };
22
-
23
- export const FLOATING_PLACEMENT = {
24
- TOP: 'top',
25
- TOP_START: 'top-start',
26
- TOP_END: 'top-end',
27
- RIGHT: 'right',
28
- RIGHT_START: 'right-start',
29
- RIGHT_END: 'right-end',
30
- BOTTOM: 'bottom',
31
- BOTTOM_START: 'bottom-start',
32
- BOTTOM_END: 'bottom-end',
33
- LEFT: 'left',
34
- LEFT_START: 'left-start',
35
- LEFT_END: 'left-end',
36
- } as const;
37
-
38
- export type FloatingPlacement = typeof FLOATING_PLACEMENT[keyof typeof FLOATING_PLACEMENT];
39
-
40
- interface FloatingComponentWrapProps {
41
- showInPortal?: boolean;
42
- className?: string;
43
- style?: CSSProperties;
44
- onClick?: (e: MouseEvent<HTMLElement>) => void;
45
- children: ReactNode;
46
- }
47
-
48
- export interface FloatingComponentBaseProps {
49
- placement?: FloatingPlacement;
50
- autoPlacements?: FloatingPlacement[];
51
- strategy?: Strategy;
52
- content?: ReactNode | string;
53
- children?: ReactNode;
54
- isOpen?: boolean;
55
- triggerRef?: RefObject<HTMLDivElement>;
56
- className?: string;
57
- offsetPx?: number;
58
- contentWrapClassName?: string;
59
- CloseButtonComponent?: ComponentType;
60
- showInPortal?: boolean;
61
- }
62
-
63
- const FloatingComponentWrapStyled = styled.span`
64
- padding: ${theme.space.space16};
65
- ${theme.typography.shared.mobile.bodyM};
66
- border-radius: 0.8rem;
67
- z-index: 999;
68
- white-space: normal;
69
- word-break: break-word;
70
- cursor: default;
71
-
72
- @media ${theme.device.tablet} {
73
- ${theme.typography.shared.tablet.bodyM};
74
- }
75
-
76
- @media ${theme.device.desktop} {
77
- ${theme.typography.shared.desktop.bodyM};
78
- }
79
- `;
80
-
81
- const ChildrenWrap = styled.div`
82
- width: fit-content;
83
- `;
84
-
85
- const StyledPopoverBox = styled.div`
86
- display: flex;
87
- align-items: center;
88
- gap: ${theme.space.space4};
89
- button {
90
- color: inherit;
91
- }
92
- `;
93
-
94
- const FloatingComponentWrap = forwardRef<HTMLSpanElement, FloatingComponentWrapProps>((props, ref) => {
95
- const { showInPortal, ...rest } = props;
96
- const component = <FloatingComponentWrapStyled {...rest} ref={ref} />;
97
- if (showInPortal) {
98
- return <FloatingPortal>{component}</FloatingPortal>;
99
- }
100
- return component;
101
- });
102
-
103
- FloatingComponentWrap.displayName = 'FloatingComponentWrap';
104
-
105
- /**
106
- * This is just the base component for Tooltips and Popovers.
107
- * Don't use this - use Tooltip/HelpPopover instead.
108
- */
109
- export const FloatingComponentBase = ({
110
- placement = FLOATING_PLACEMENT.TOP,
111
- autoPlacements,
112
- strategy = 'fixed',
113
- content,
114
- children,
115
- isOpen = false,
116
- triggerRef,
117
- className,
118
- offsetPx = 10,
119
- contentWrapClassName,
120
- CloseButtonComponent,
121
- showInPortal = false,
122
- }: FloatingComponentBaseProps) => {
123
- const {
124
- x,
125
- y,
126
- refs: { setReference, setFloating },
127
- strategy: effectiveStrategy,
128
- middlewareData: {
129
- hide: refHidden,
130
- },
131
- context,
132
- } = useFloating({
133
- open: isOpen,
134
- placement,
135
- strategy,
136
- whileElementsMounted: autoUpdate,
137
- middleware: [
138
- offset(offsetPx),
139
- autoPlacements?.length ? autoPlacement({ allowedPlacements: autoPlacements }) : flip(),
140
- shift({ padding: 5 }),
141
- hide({
142
- strategy: 'referenceHidden',
143
- }),
144
- ],
145
- });
146
-
147
- const { isMounted, styles } = useTransitionStyles(context, {
148
- initial: ({ side }) => {
149
- switch (side) {
150
- case 'top':
151
- return { opacity: 0, scale: '0.9', transform: 'translateY(10px)' };
152
- case 'bottom':
153
- return { opacity: 0, scale: '0.9', transform: 'translateY(-10px)' };
154
- case 'left':
155
- return { opacity: 0, scale: '0.9', transform: 'translateX(10px)' };
156
- case 'right':
157
- return { opacity: 0, scale: '0.9', transform: 'translateX(-10px)' };
158
- default:
159
- return {};
160
- }
161
- },
162
- });
163
-
164
- if (!content) return <span>{children}</span>;
165
-
166
- return (
167
- <>
168
- {/* Adding className to children for easier identifying in DevTools */}
169
- <ChildrenWrap className={clsx(classNames.CHILDREN, contentWrapClassName)} ref={setReference}>
170
- {children}
171
- </ChildrenWrap>
172
- { isMounted && (
173
- <FloatingComponentWrap
174
- className={className}
175
- ref={setFloating}
176
- style={{
177
- position: effectiveStrategy,
178
- top: y ?? 0,
179
- left: x ?? 0,
180
- width: 'max-content',
181
- visibility: refHidden?.referenceHidden ? 'hidden' : 'visible',
182
- ...styles,
183
- }}
184
- onClick={(e) => e.stopPropagation()}
185
- showInPortal={showInPortal}
186
- >
187
- <div ref={triggerRef}>
188
- {CloseButtonComponent
189
- ? <StyledPopoverBox>
190
- {content}
191
- <CloseButtonComponent />
192
- </StyledPopoverBox>
193
- : content}
194
- </div>
195
- </FloatingComponentWrap>
196
- )}
197
- </>
198
- );
199
- };
@@ -1,130 +0,0 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
-
4
- import { FLOATING_PLACEMENT } from './floating_component_base.tsx';
5
- import { Tooltip } from './tooltip.tsx';
6
-
7
- const Child = () => <div style={{ padding: '8px', border: '1px solid black', borderRadius: '4px' }}>Hover me</div>;
8
-
9
- const longText = 'This is a tooltip with a longer text. This is a tooltip with a longer text. This is a tooltip with a longer text.';
10
-
11
- export default {
12
- title: 'UI-Library/Tooltip',
13
- component: Tooltip,
14
- parameters: {
15
- design: {
16
- type: 'figma',
17
- url: 'https://www.figma.com/design/duSsGnk84UMYav8mg8QNgR/%F0%9F%93%96-Shared-library?node-id=5236-98464&p=f&m=dev',
18
- },
19
- },
20
- decorators: [
21
- (Story) => (
22
- <div style={{ margin: '5em', width: 'fit-content' }}>
23
- <Story />
24
- </div>
25
- ),
26
- ],
27
- args: {
28
- children: <Child />,
29
- content: 'This is a tooltip',
30
- isDarkTheme: false,
31
- },
32
- };
33
-
34
- const DefaultStoryWrapper = styled.div`
35
- display: grid;
36
- grid-template-columns: 1fr 1fr 1fr;
37
- gap: 10em;
38
- row-gap: 20em;
39
- `;
40
-
41
- export const Default = (args) => {
42
- return (<DefaultStoryWrapper>
43
- <div>
44
- <Tooltip {...args}/>
45
- Default
46
- </div>
47
- <div>
48
- <Tooltip shortcuts={['Ctrl / ⌘', 'F']} {...args}/>
49
- With shortcuts
50
- </div>
51
- <div>
52
- <Tooltip subtleText="This is some subtle text" {...args} />
53
- With subtleText
54
- </div>
55
- <div>
56
- <Tooltip imageUrl='https://picsum.photos/id/1/1024' {...args} />
57
- With image
58
- </div>
59
- <div>
60
- <Tooltip
61
- persistent={{ isOpenOverride: true }}
62
- shortcuts={['Ctrl / ⌘', 'F']}
63
- content={longText}
64
- textAlign='center'
65
- ><Child /></Tooltip>
66
- With shortcuts and long centered text
67
- </div>
68
- <div>
69
- <Tooltip
70
- persistent={{ isOpenOverride: true }}
71
- shortcuts={['Ctrl / ⌘', 'F']}
72
- imageUrl='https://picsum.photos/id/1/1024'
73
- subtleText="This is some subtle text"
74
- placement={FLOATING_PLACEMENT.BOTTOM}
75
- content={longText}
76
- ><Child /></Tooltip>
77
- With everything
78
- </div>
79
- </DefaultStoryWrapper>
80
- );
81
- };
82
- Default.args = {
83
- persistent: { isOpenOverride: true },
84
- };
85
-
86
- export const Sizes = () => {
87
- return (<DefaultStoryWrapper>
88
- <div>
89
- Xsmall:
90
- <Tooltip size="xsmall" content={longText}><Child /></Tooltip>
91
- </div>
92
- <div>
93
- Small (default):
94
- <Tooltip size="small" content={longText}><Child /></Tooltip>
95
- </div>
96
- <div>
97
- Medium:
98
- <Tooltip size="medium" content={longText}><Child /></Tooltip>
99
- </div>
100
- <div>
101
- Large:
102
- <Tooltip size="large" content={longText}><Child /></Tooltip>
103
- </div>
104
- <div>
105
- Xlarge:
106
- <Tooltip size="xlarge" content={longText}><Child /></Tooltip>
107
- </div>
108
- </DefaultStoryWrapper>
109
- );
110
- };
111
-
112
- export const Playground = (args) => {
113
- return (
114
- <Tooltip {...args}/>
115
- );
116
- };
117
- Playground.argTypes = {
118
- content: { control: 'text' },
119
- shortcuts: { control: 'array' },
120
- imageUrl: { control: 'text' },
121
- subtleText: { control: 'text' },
122
- size: {
123
- control: 'select',
124
- options: ['xsmall', 'small', 'medium', 'large', 'xlarge'],
125
- },
126
- placement: {
127
- control: 'select',
128
- options: Object.values(FLOATING_PLACEMENT),
129
- },
130
- };
@@ -1,146 +0,0 @@
1
- import {
2
- useFloating,
3
- useHover,
4
- useInteractions,
5
- } from '@floating-ui/react';
6
- import { type ComponentType, forwardRef, useState } from 'react';
7
- import styled, { css } from 'styled-components';
8
-
9
- import { theme } from '../../design_system/theme.js';
10
- import { useSharedUiDependencies } from '../../ui_dependency_provider.js';
11
- import { FloatingComponentBase, type FloatingComponentBaseProps } from './floating_component_base.js';
12
- import { TooltipContent } from './tooltip_content.js';
13
-
14
- export const TOOLTIP_TEXT_ALIGNS = {
15
- LEFT: 'left',
16
- CENTER: 'center',
17
- } as const;
18
-
19
- export type TooltipTextAlign = typeof TOOLTIP_TEXT_ALIGNS[keyof typeof TOOLTIP_TEXT_ALIGNS];
20
-
21
- export const TOOLTIP_SIZES = {
22
- XSMALL: 'xsmall',
23
- SMALL: 'small',
24
- MEDIUM: 'medium',
25
- LARGE: 'large', /* Previously WIDE */
26
- XLARGE: 'xlarge', /* Previously WIDER */
27
- } as const;
28
-
29
- export type TooltipSize = typeof TOOLTIP_SIZES[keyof typeof TOOLTIP_SIZES];
30
-
31
- interface PersistentTooltipProps {
32
- isOpenOverride?: boolean;
33
- CloseButtonComponent?: ComponentType;
34
- }
35
-
36
- export interface TooltipProps extends Omit<FloatingComponentBaseProps, 'isOpen' | 'size'> {
37
- as?: keyof JSX.IntrinsicElements | ComponentType<unknown>;
38
- className?: string;
39
- persistent?: PersistentTooltipProps;
40
- delayShow?: number;
41
- delayHide?: number;
42
- shortcuts?: string[];
43
- imageUrl?: string;
44
- subtleText?: string;
45
- size?: TooltipSize;
46
- textAlign?: TooltipTextAlign;
47
- }
48
-
49
- interface WithTooltipProps {
50
- tooltipProps?: TooltipProps;
51
- }
52
-
53
- // Using a styled component to get access to the `as` prop
54
- const TooltipFocusArea = styled.span``;
55
-
56
- const StyledFloatingComponentBase = styled(FloatingComponentBase)<{ $isDarkTheme?: boolean }>`
57
- color: ${theme.colorPalette.dark.neutral0};
58
- background-color: ${theme.colorPalette.dark.neutral900};
59
- padding: ${theme.space.space8};
60
-
61
- ${({ $isDarkTheme }) => $isDarkTheme && css`
62
- box-shadow: ${theme.shadow.shadow2};
63
- border: 1px solid ${theme.color.neutral.smallTooltipBorder};
64
- `}
65
- `;
66
-
67
- /**
68
- * Tooltip appears on hover, for onclick use Popover
69
- */
70
- export const Tooltip = ({
71
- as,
72
- className,
73
- persistent,
74
- delayShow = 500,
75
- delayHide = 50,
76
- shortcuts = [],
77
- imageUrl,
78
- subtleText,
79
- size = TOOLTIP_SIZES.SMALL,
80
- textAlign = TOOLTIP_TEXT_ALIGNS.LEFT,
81
- ...rest
82
- }: TooltipProps) => {
83
- const { uiTheme } = useSharedUiDependencies();
84
- const { isOpenOverride, CloseButtonComponent } = persistent || {};
85
- const [open, setOpen] = useState(false);
86
-
87
- const { refs, context } = useFloating({
88
- open,
89
- onOpenChange: setOpen,
90
- });
91
-
92
- const hover = useHover(context, {
93
- delay: {
94
- open: delayShow,
95
- close: delayHide,
96
- },
97
- });
98
-
99
- const { getReferenceProps, getFloatingProps } = useInteractions([hover]);
100
-
101
- const tooltipProps = {
102
- ...rest,
103
- isOpen: isOpenOverride !== undefined ? isOpenOverride : open,
104
- content: <TooltipContent
105
- content={rest.content}
106
- shortcuts={shortcuts}
107
- imageUrl={imageUrl}
108
- subtleText={subtleText}
109
- size={size}
110
- textAlign={textAlign}
111
- />,
112
- };
113
-
114
- return (
115
- <TooltipFocusArea
116
- as={as as keyof JSX.IntrinsicElements}
117
- className={className}
118
- ref={refs.setReference}
119
- {...getReferenceProps()}
120
- >
121
- <div
122
- ref={refs.setFloating}
123
- {...getFloatingProps()}
124
- >
125
- <StyledFloatingComponentBase
126
- {...tooltipProps}
127
- CloseButtonComponent={CloseButtonComponent}
128
- $isDarkTheme={uiTheme === 'DARK'}
129
- />
130
- </div>
131
- </TooltipFocusArea>
132
- );
133
- };
134
-
135
- export function withTooltip<TProps extends Record<string, unknown> = Record<string, unknown>>(Component: ComponentType<TProps>) {
136
- const Enhanced = forwardRef<HTMLElement, TProps & WithTooltipProps>(({ tooltipProps, ...rest }, ref) => {
137
- if (!tooltipProps) return <Component {...(rest as unknown as TProps)} ref={ref} />;
138
- return <Tooltip {...tooltipProps}>
139
- <Component {...(rest as unknown as TProps)} ref={ref} />
140
- </Tooltip>;
141
- });
142
-
143
- Enhanced.displayName = `WithTooltip:${Component.displayName || Component.name}`;
144
-
145
- return Enhanced;
146
- }
@@ -1,103 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
-
3
- import { theme } from '../../design_system/theme.js';
4
- import { Shortcut } from '../shortcut.js';
5
- import type { TooltipProps, TooltipSize, TooltipTextAlign } from './tooltip.js';
6
- import { TOOLTIP_SIZES, TOOLTIP_TEXT_ALIGNS } from './tooltip.js';
7
-
8
- type ContentProps = Pick<TooltipProps, 'content' | 'shortcuts' | 'imageUrl' | 'subtleText' | 'size' | 'textAlign'>;
9
-
10
- const TOOLTIP_SIZES_VALUES: Record<TooltipSize, string> = {
11
- xsmall: '24rem',
12
- small: '32rem',
13
- medium: '40rem',
14
- large: '48rem',
15
- xlarge: '64rem',
16
- };
17
-
18
- const TOOLTIP_CLASSNAMES = {
19
- IMAGE: 'Tooltip-image',
20
- TEXT_CONTENT: 'Tooltip-textContent',
21
- SUBTLE_TEXT: 'Tooltip-subtleText',
22
- SHORTCUT_CONTAINER: 'Tooltip-shortcutContainer',
23
- } as const;
24
-
25
- const StyledContent = styled.div<{ $size: TooltipSize, $textAlign: TooltipTextAlign }>`
26
- display: flex;
27
- flex-direction: column;
28
- gap: ${theme.space.space8};
29
- /* Size - (tooltip padding + border) * 2 */
30
- max-width: ${({ $size }) => css`calc(${TOOLTIP_SIZES_VALUES[$size]} - (${theme.space.space8} + 1px) * 2)`};
31
- text-align: ${({ $textAlign }) => $textAlign || 'left'};
32
- align-items: ${({ $textAlign }) => ($textAlign === 'center' ? 'center' : 'flex-start')};
33
-
34
- .${TOOLTIP_CLASSNAMES.IMAGE} {
35
- max-width: 100%;
36
- max-height: 150px;
37
- border-radius: 4px;
38
- object-fit: contain;
39
- }
40
-
41
- .${TOOLTIP_CLASSNAMES.TEXT_CONTENT} {
42
- display: flex;
43
- flex-direction: column;
44
- gap: ${theme.space.space8};
45
- align-items: ${({ $textAlign }) => ($textAlign === 'center' ? 'center' : 'flex-start')};
46
-
47
- /* When there is no child with subtleText class */
48
- &:not(:has(.${TOOLTIP_CLASSNAMES.SUBTLE_TEXT})){
49
- flex-direction: row;
50
- flex-wrap: wrap;
51
- }
52
-
53
- /* When there is a child with subtleText class */
54
- &:has(.${TOOLTIP_CLASSNAMES.SUBTLE_TEXT}){
55
- text-align: left;
56
- }
57
-
58
- .${TOOLTIP_CLASSNAMES.SUBTLE_TEXT} {
59
- color: ${theme.colorPalette.dark.neutral500};
60
- }
61
-
62
- .${TOOLTIP_CLASSNAMES.SHORTCUT_CONTAINER} {
63
- display: flex;
64
- gap: ${theme.space.space4};
65
- }
66
- }
67
- `;
68
-
69
- export const TooltipContent = ({
70
- content,
71
- shortcuts = [],
72
- imageUrl,
73
- subtleText,
74
- size = TOOLTIP_SIZES.SMALL,
75
- textAlign = TOOLTIP_TEXT_ALIGNS.LEFT,
76
- }: ContentProps) => {
77
- return (
78
- <StyledContent $size={size} $textAlign={textAlign}>
79
- {imageUrl && (
80
- <img
81
- src={imageUrl}
82
- alt=""
83
- className={TOOLTIP_CLASSNAMES.IMAGE}
84
- />
85
- )}
86
- <div className={TOOLTIP_CLASSNAMES.TEXT_CONTENT}>
87
- {content}
88
- {subtleText && (
89
- <div className={TOOLTIP_CLASSNAMES.SUBTLE_TEXT}>
90
- {subtleText}
91
- </div>
92
- )}
93
- {shortcuts.length > 0 && (
94
- <div className={TOOLTIP_CLASSNAMES.SHORTCUT_CONTAINER}>
95
- {shortcuts.map((shortcut, index) => (
96
- <Shortcut key={`${shortcut}-${index}`} dark>{shortcut}</Shortcut>
97
- ))}
98
- </div>
99
- )}
100
- </div>
101
- </StyledContent>
102
- );
103
- };
@@ -1,58 +0,0 @@
1
- import React from 'react';
2
-
3
- import { theme } from '../design_system/theme.ts';
4
- import { Shortcut } from './shortcut.tsx';
5
-
6
- export default {
7
- title: 'UI-Library/Shortcut',
8
- component: Shortcut,
9
- parameters: {
10
- design: {
11
- type: 'figma',
12
- url: 'https://www.figma.com/design/duSsGnk84UMYav8mg8QNgR/%F0%9F%93%96-Shared-library?node-id=5236-100844&m=dev',
13
- },
14
- },
15
- };
16
-
17
- export const ShortcutComponent = () => {
18
- return (<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
19
- Default:
20
- <div style={{ display: 'flex', gap: '4px', padding: '16px' }}>
21
- <Shortcut>F</Shortcut>
22
- <Shortcut>Ctrl / ⌘</Shortcut>
23
- <Shortcut>Shift</Shortcut>
24
- </div>
25
- Dark:
26
- <div style={{ display: 'flex', gap: '4px', backgroundColor: theme.colorPalette.dark.neutral700, padding: '16px' }}>
27
- <Shortcut dark>F</Shortcut>
28
- <Shortcut dark>Ctrl / ⌘</Shortcut>
29
- <Shortcut dark>Shift</Shortcut>
30
- </div>
31
- </div>);
32
- };
33
-
34
- export const Playground = (args) => {
35
- return (<Shortcut {...args}/>);
36
- };
37
- Playground.args = {
38
- children: 'F',
39
- dark: false,
40
- as: 'div',
41
- };
42
- Playground.argTypes = {
43
- dark: {
44
- control: 'boolean',
45
- defaultValue: false,
46
- },
47
- as: {
48
- control: 'text',
49
- defaultValue: 'div',
50
- },
51
- children: {
52
- control: 'text',
53
- defaultValue: 'F',
54
- },
55
- className: {
56
- control: 'text',
57
- },
58
- };
@@ -1,55 +0,0 @@
1
- import styled, { css } from 'styled-components';
2
-
3
- import { theme } from '../design_system/theme.js';
4
- import { Text } from './text/index.js';
5
-
6
- interface ShortcutProps {
7
- as?: keyof JSX.IntrinsicElements;
8
- className?: string;
9
- children: React.ReactNode;
10
- /* If true, always use dark mode colors */
11
- dark?: boolean;
12
- }
13
-
14
- const adaptiveColors = css`
15
- background-color: ${theme.color.neutral.backgroundSubtle};
16
- border: 1px solid ${theme.color.neutral.border};
17
- color: ${theme.color.neutral.textSubtle};
18
- `;
19
-
20
- /* Tooltips with shortcuts use dark mode styles */
21
- const darkColors = css`
22
- background-color: ${theme.colorPalette.dark.neutral800};
23
- border: 1px solid ${theme.colorPalette.dark.neutral700};
24
- color: ${theme.colorPalette.dark.neutral400};
25
- `;
26
-
27
- const StyledShortcut = styled(Text)<{ $dark?: boolean }>`
28
- min-width: 10px; /* 20 - paddings - borders */
29
- height: 14px; /* 20 - paddings - borders */
30
- display: inline-flex;
31
- align-items: center;
32
- justify-content: center;
33
- border-radius: ${theme.radius.radius4};
34
- padding: ${theme.space.space2} ${theme.space.space4};
35
- ${({ $dark }) => ($dark ? darkColors : adaptiveColors)}
36
- `;
37
-
38
- export const Shortcut = ({
39
- as,
40
- className,
41
- children,
42
- dark = false,
43
- }: ShortcutProps) => {
44
- return (
45
- <StyledShortcut
46
- forwardedAs={as}
47
- className={className}
48
- $dark={dark}
49
- type='code'
50
- size='small'
51
- weight='medium'>
52
- {children}
53
- </StyledShortcut>
54
- );
55
- };