Skip to content

Commit

Permalink
feat: share button description text
Browse files Browse the repository at this point in the history
  • Loading branch information
avlyalin committed Jun 5, 2020
1 parent 86d6216 commit dde6e5b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/components/form-group/form-group.ispec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const customConfig = {
failureThreshold: 0.01,
failureThresholdType: 'percent',
};

describe('<FormGroup /> visually looks correct', () => {
test('without description text', async () => {
await page.goto(
'http://localhost:9009/iframe.html?path=/story/components-form-group--without-description&&knob-Description position=end&knob-Label=Your name',
);
const formGroup = await page.$('[data-testid=form-group]');
const image = await formGroup.screenshot();
expect(image).toMatchImageSnapshot(customConfig);
});
test('with description text on left', async () => {
await page.goto(
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=start&knob-Label=Your name',
);
const formGroup = await page.$('[data-testid=form-group]');
const image = await formGroup.screenshot();
expect(image).toMatchImageSnapshot(customConfig);
});
test('with description text on center', async () => {
await page.goto(
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=center&knob-Label=Your name',
);
const formGroup = await page.$('[data-testid=form-group]');
const image = await formGroup.screenshot();
expect(image).toMatchImageSnapshot(customConfig);
});
test('with description text on right', async () => {
await page.goto(
'http://localhost:9009/iframe.html?path=/story/components-form-group--with-description&&knob-Description position=end&knob-Label=Your name',
);
const formGroup = await page.$('[data-testid=form-group]');
const image = await formGroup.screenshot();
expect(image).toMatchImageSnapshot(customConfig);
});
});
31 changes: 29 additions & 2 deletions src/components/form-group/form-group.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const FormGroup = React.forwardRef(function FormGroup(props, ref) {
const { label, labelFor, children, childrenContainerClass, ...other } = props;
const {
description = '',
descriptionPosition = 'start',
label,
labelFor,
children,
childrenContainerClass,
...other
} = props;
const childrenCount = React.Children.count(children);
const labelClasses = 'text-sm text-gray-400 mb-2';
let content;
Expand All @@ -25,13 +34,31 @@ const FormGroup = React.forwardRef(function FormGroup(props, ref) {
}

return (
<div className="flex flex-col" ref={ref} {...other}>
<div
data-testid={'form-group'}
className="flex flex-col"
ref={ref}
{...other}
>
{content}
{description && (
<span
className={classnames('text-sm text-gray-300 mt-2', {
'self-start': descriptionPosition === 'start',
'self-center': descriptionPosition === 'center',
'self-end': descriptionPosition === 'end',
})}
>
{description}
</span>
)}
</div>
);
});

FormGroup.propTypes = {
description: PropTypes.string,
descriptionPosition: PropTypes.oneOf(['start', 'center', 'end']),
label: PropTypes.node,
labelFor: PropTypes.string,
childrenContainerClass: PropTypes.string,
Expand Down
55 changes: 52 additions & 3 deletions src/components/form-group/form-group.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { withKnobs, text } from '@storybook/addon-knobs';
import { withKnobs, text, radios } from '@storybook/addon-knobs';
import { containerDecorator } from '_storybook/container';
import { Input } from '../input';
import { FormGroup } from './form-group';
Expand All @@ -11,20 +11,22 @@ export default {
};

export const WithSingleChildren = () => {
const description = text('Description', 'helper text');
const label = text('Label', 'Your name');
return (
<FormGroup label={label} labelFor="input-1">
<FormGroup label={label} labelFor="input-1" description={description}>
<Input id="input-1" />
</FormGroup>
);
};

export const WithMultipleChildren = () => {
const description = text('Description', 'helper text');
const label = text('Label', 'Options');
let value = 'option-1';
const onChange = () => {};
return (
<FormGroup label={label} labelFor="input-1">
<FormGroup label={label} labelFor="input-1" description={description}>
<input
id="option-1"
type="checkbox"
Expand All @@ -44,3 +46,50 @@ export const WithMultipleChildren = () => {
</FormGroup>
);
};

export const WithDescription = () => {
const description = text('Description', 'helper text');
const descriptionPosition = radios(
'Description position',
{
start: 'start',
center: 'center',
end: 'end',
},
'end',
);
const label = text('Label', 'Your name');
return (
<FormGroup
label={label}
labelFor="input-1"
description={description}
descriptionPosition={descriptionPosition}
>
<Input id="input-1" />
</FormGroup>
);
};
export const WithoutDescription = () => {
const description = text('Description', '');
const descriptionPosition = radios(
'Description position',
{
start: 'start',
center: 'center',
end: 'end',
},
'end',
);
const label = text('Label', 'Your name');
return (
<FormGroup
label={label}
labelFor="input-1"
description={description}
descriptionPosition={descriptionPosition}
>
<Input id="input-1" />
</FormGroup>
);
};
7 changes: 6 additions & 1 deletion src/containers/lobby/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function Lobby({
}

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

return (
<div
Expand All @@ -76,7 +77,11 @@ function Lobby({
)}
>
<div className={'mt-6 row-start-1 col-start-1'}>
<FormGroup label={'ID сессии'}>
<FormGroup
description={shareDescription}
descriptionPosition={'end'}
label={'ID сессии'}
>
<InputGroup
append={
<Button
Expand Down

0 comments on commit dde6e5b

Please sign in to comment.