Skip to content

Commit 176200d

Browse files
authored
fix: copy button and long value components fixes (#219)
1 parent 53b4dc0 commit 176200d

File tree

6 files changed

+57
-44
lines changed

6 files changed

+57
-44
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
@import '../../styles/variables.scss';
22

33
.#{$ns}copy-button {
4+
width: 20px;
45
display: none;
5-
margin: 2px 0 0 5px;
6+
position: relative;
7+
margin: -1px 0 0 5px;
8+
9+
&__button {
10+
position: absolute;
11+
top: 0;
12+
left: 0;
13+
}
614
}

src/lib/kit/components/CopyButton/CopyButton.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export interface CopyButtonProps {
2121

2222
export const CopyButton: React.FC<CopyButtonProps> = ({spec, value}) => {
2323
if ((isStringSpec(spec) || isNumberSpec(spec)) && spec.viewSpec.copy) {
24-
return <ClipboardButton className={b()} text={`${value}`} size="s" />;
24+
return (
25+
<div className={b()}>
26+
<ClipboardButton className={b('button')} text={`${value}`} size="xs" />
27+
</div>
28+
);
2529
}
2630

2731
return null;

src/lib/kit/components/LongValue/LongValue.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
.#{$ns}long-value {
44
max-width: 100%;
5+
overflow: hidden;
6+
text-overflow: ellipsis;
7+
8+
&_open {
9+
white-space: pre-wrap;
10+
word-wrap: break-word;
11+
}
512

613
&_long {
714
cursor: pointer;
@@ -10,8 +17,4 @@
1017
color: var(--g-color-text-secondary);
1118
}
1219
}
13-
14-
&__container {
15-
display: flex;
16-
}
1720
}

src/lib/kit/components/LongValue/LongValue.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ export const LongValue: React.FC<LongValueProps> = ({value, className}) => {
2121

2222
const handleClick = React.useCallback(() => setOpen((f) => !f), [setOpen]);
2323

24-
const currentTextProperies = React.useMemo(() => {
25-
let wordBreak: 'break-all' | undefined;
26-
let whiteSpace: 'break-spaces' | undefined;
27-
28-
if (open) {
29-
wordBreak = 'break-all';
30-
whiteSpace = 'break-spaces';
31-
}
32-
33-
return {wordBreak, whiteSpace};
34-
}, [open]);
35-
3624
React.useEffect(() => {
3725
if (ref.current) {
3826
if (value !== prevValue.current) {
@@ -58,10 +46,14 @@ export const LongValue: React.FC<LongValueProps> = ({value, className}) => {
5846
});
5947

6048
return (
61-
<div className={b('container')} ref={ref} onClick={long ? handleClick : undefined}>
62-
<Text className={b({long}, className)} ellipsis={true} {...currentTextProperies}>
63-
{value}
64-
</Text>
65-
</div>
49+
<Text
50+
as="div"
51+
ref={ref}
52+
className={b({open, long}, className)}
53+
// @ts-ignore
54+
onClick={long ? handleClick : undefined}
55+
>
56+
{value}
57+
</Text>
6658
);
6759
};

src/stories/components/Editor/Editor.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,26 @@ export const Editor: React.FC<EditorProps> = ({spec: externalSpec, value, viewMo
159159
/>
160160
</div>
161161
) : null}
162-
<div className={b('input-view', {hidden: toggler !== 'view'})}>
163-
<Flex gap={1} spacing={{mb: 6}}>
164-
<Text variant="body-2">Enable showLayoutDescription props</Text>
165-
<Switch
166-
onChange={() => setShowLayoutDescription((v) => !v)}
167-
className={b('switch')}
162+
{toggler === 'view' ? (
163+
<div className={b('input-view')}>
164+
<Flex gap={1} spacing={{mb: 6}}>
165+
<Text variant="body-2">
166+
Enable showLayoutDescription props
167+
</Text>
168+
<Switch
169+
onChange={() => setShowLayoutDescription((v) => !v)}
170+
className={b('switch')}
171+
/>
172+
</Flex>
173+
<DynamicView
174+
{...getViewProps(
175+
form.values.input,
176+
spec,
177+
showLayoutDescription,
178+
)}
168179
/>
169-
</Flex>
170-
<DynamicView
171-
{...getViewProps(
172-
form.values.input,
173-
spec,
174-
showLayoutDescription,
175-
)}
176-
/>
177-
</div>
180+
</div>
181+
) : null}
178182
{toggler === 'json' ? (
179183
<div className={b('monaco')}>
180184
<MonacoInput {...getValuesEditorProps(form.values.input)} />

src/stories/components/InputPreview/InputPreview.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ export const InputPreview: React.FC<InputPreviewProps> = ({
175175
search={searchInput}
176176
/>
177177
</div>
178-
<div className={b('input-view', {hidden: togglerInput !== 'view'})}>
179-
<DynamicView
180-
value={form.values.input}
181-
spec={transformIncorrect(form.values.options)}
182-
/>
183-
</div>
178+
{togglerInput === 'view' ? (
179+
<div className={b('input-view')}>
180+
<DynamicView
181+
value={form.values.input}
182+
spec={transformIncorrect(form.values.options)}
183+
/>
184+
</div>
185+
) : null}
184186
{togglerInput === 'json' ? (
185187
<div className={b('monaco')}>{renderMonaco(form.values.input)}</div>
186188
) : null}

0 commit comments

Comments
 (0)