Skip to content

Commit dde6e5b

Browse files
committed
feat: share button description text
1 parent 86d6216 commit dde6e5b

8 files changed

+126
-6
lines changed
Loading
Loading
Loading
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const customConfig = {
2+
failureThreshold: 0.01,
3+
failureThresholdType: 'percent',
4+
};
5+
6+
describe('<FormGroup /> visually looks correct', () => {
7+
test('without description text', async () => {
8+
await page.goto(
9+
'http://localhost:9009/iframe.html?path=/story/components-form-group--without-description&&knob-Description position=end&knob-Label=Your name',
10+
);
11+
const formGroup = await page.$('[data-testid=form-group]');
12+
const image = await formGroup.screenshot();
13+
expect(image).toMatchImageSnapshot(customConfig);
14+
});
15+
test('with description text on left', async () => {
16+
await page.goto(
17+
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=start&knob-Label=Your name',
18+
);
19+
const formGroup = await page.$('[data-testid=form-group]');
20+
const image = await formGroup.screenshot();
21+
expect(image).toMatchImageSnapshot(customConfig);
22+
});
23+
test('with description text on center', async () => {
24+
await page.goto(
25+
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=center&knob-Label=Your name',
26+
);
27+
const formGroup = await page.$('[data-testid=form-group]');
28+
const image = await formGroup.screenshot();
29+
expect(image).toMatchImageSnapshot(customConfig);
30+
});
31+
test('with description text on right', async () => {
32+
await page.goto(
33+
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=end&knob-Label=Your name',
34+
);
35+
const formGroup = await page.$('[data-testid=form-group]');
36+
const image = await formGroup.screenshot();
37+
expect(image).toMatchImageSnapshot(customConfig);
38+
});
39+
});

src/components/form-group/form-group.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import classnames from 'classnames';
34

45
const FormGroup = React.forwardRef(function FormGroup(props, ref) {
5-
const { label, labelFor, children, childrenContainerClass, ...other } = props;
6+
const {
7+
description = '',
8+
descriptionPosition = 'start',
9+
label,
10+
labelFor,
11+
children,
12+
childrenContainerClass,
13+
...other
14+
} = props;
615
const childrenCount = React.Children.count(children);
716
const labelClasses = 'text-sm text-gray-400 mb-2';
817
let content;
@@ -25,13 +34,31 @@ const FormGroup = React.forwardRef(function FormGroup(props, ref) {
2534
}
2635

2736
return (
28-
<div className="flex flex-col" ref={ref} {...other}>
37+
<div
38+
data-testid={'form-group'}
39+
className="flex flex-col"
40+
ref={ref}
41+
{...other}
42+
>
2943
{content}
44+
{description && (
45+
<span
46+
className={classnames('text-sm text-gray-300 mt-2', {
47+
'self-start': descriptionPosition === 'start',
48+
'self-center': descriptionPosition === 'center',
49+
'self-end': descriptionPosition === 'end',
50+
})}
51+
>
52+
{description}
53+
</span>
54+
)}
3055
</div>
3156
);
3257
});
3358

3459
FormGroup.propTypes = {
60+
description: PropTypes.string,
61+
descriptionPosition: PropTypes.oneOf(['start', 'center', 'end']),
3562
label: PropTypes.node,
3663
labelFor: PropTypes.string,
3764
childrenContainerClass: PropTypes.string,

src/components/form-group/form-group.stories.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { withKnobs, text } from '@storybook/addon-knobs';
2+
import { withKnobs, text, radios } from '@storybook/addon-knobs';
33
import { containerDecorator } from '_storybook/container';
44
import { Input } from '../input';
55
import { FormGroup } from './form-group';
@@ -11,20 +11,22 @@ export default {
1111
};
1212

1313
export const WithSingleChildren = () => {
14+
const description = text('Description', 'helper text');
1415
const label = text('Label', 'Your name');
1516
return (
16-
<FormGroup label={label} labelFor="input-1">
17+
<FormGroup label={label} labelFor="input-1" description={description}>
1718
<Input id="input-1" />
1819
</FormGroup>
1920
);
2021
};
2122

2223
export const WithMultipleChildren = () => {
24+
const description = text('Description', 'helper text');
2325
const label = text('Label', 'Options');
2426
let value = 'option-1';
2527
const onChange = () => {};
2628
return (
27-
<FormGroup label={label} labelFor="input-1">
29+
<FormGroup label={label} labelFor="input-1" description={description}>
2830
<input
2931
id="option-1"
3032
type="checkbox"
@@ -44,3 +46,50 @@ export const WithMultipleChildren = () => {
4446
</FormGroup>
4547
);
4648
};
49+
50+
export const WithDescription = () => {
51+
const description = text('Description', 'helper text');
52+
const descriptionPosition = radios(
53+
'Description position',
54+
{
55+
start: 'start',
56+
center: 'center',
57+
end: 'end',
58+
},
59+
'end',
60+
);
61+
const label = text('Label', 'Your name');
62+
return (
63+
<FormGroup
64+
label={label}
65+
labelFor="input-1"
66+
description={description}
67+
descriptionPosition={descriptionPosition}
68+
>
69+
<Input id="input-1" />
70+
</FormGroup>
71+
);
72+
};
73+
export const WithoutDescription = () => {
74+
const description = text('Description', '');
75+
const descriptionPosition = radios(
76+
'Description position',
77+
{
78+
start: 'start',
79+
center: 'center',
80+
end: 'end',
81+
},
82+
'end',
83+
);
84+
const label = text('Label', 'Your name');
85+
return (
86+
<FormGroup
87+
label={label}
88+
labelFor="input-1"
89+
description={description}
90+
descriptionPosition={descriptionPosition}
91+
>
92+
<Input id="input-1" />
93+
</FormGroup>
94+
);
95+
};

src/containers/lobby/lobby.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function Lobby({
5656
}
5757

5858
const shareIcon = navigator.share ? 'share-alt' : 'clone';
59+
const shareDescription = navigator.share ? 'Поделиться' : 'Копировать ссылку';
5960

6061
return (
6162
<div
@@ -76,7 +77,11 @@ function Lobby({
7677
)}
7778
>
7879
<div className={'mt-6 row-start-1 col-start-1'}>
79-
<FormGroup label={'ID сессии'}>
80+
<FormGroup
81+
description={shareDescription}
82+
descriptionPosition={'end'}
83+
label={'ID сессии'}
84+
>
8085
<InputGroup
8186
append={
8287
<Button

0 commit comments

Comments
 (0)