diff --git a/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-center-1-snap.png b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-center-1-snap.png new file mode 100644 index 0000000..16cf194 Binary files /dev/null and b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-center-1-snap.png differ diff --git a/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-left-1-snap.png b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-left-1-snap.png new file mode 100644 index 0000000..f0a80d5 Binary files /dev/null and b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-left-1-snap.png differ diff --git a/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-right-1-snap.png b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-right-1-snap.png new file mode 100644 index 0000000..93c7747 Binary files /dev/null and b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-with-description-text-on-right-1-snap.png differ diff --git a/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-without-description-text-1-snap.png b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-without-description-text-1-snap.png new file mode 100644 index 0000000..34bebb5 Binary files /dev/null and b/src/components/form-group/__image_snapshots__/form-group-ispec-js-form-group-visually-looks-correct-without-description-text-1-snap.png differ diff --git a/src/components/form-group/form-group.ispec.js b/src/components/form-group/form-group.ispec.js new file mode 100644 index 0000000..b66d68b --- /dev/null +++ b/src/components/form-group/form-group.ispec.js @@ -0,0 +1,39 @@ +const customConfig = { + failureThreshold: 0.01, + failureThresholdType: 'percent', +}; + +describe(' 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); + }); +}); diff --git a/src/components/form-group/form-group.js b/src/components/form-group/form-group.js index 317844b..aba2a3e 100644 --- a/src/components/form-group/form-group.js +++ b/src/components/form-group/form-group.js @@ -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; @@ -25,13 +34,31 @@ const FormGroup = React.forwardRef(function FormGroup(props, ref) { } return ( -
+
{content} + {description && ( + + {description} + + )}
); }); FormGroup.propTypes = { + description: PropTypes.string, + descriptionPosition: PropTypes.oneOf(['start', 'center', 'end']), label: PropTypes.node, labelFor: PropTypes.string, childrenContainerClass: PropTypes.string, diff --git a/src/components/form-group/form-group.stories.js b/src/components/form-group/form-group.stories.js index 2428e8d..42a9e5d 100644 --- a/src/components/form-group/form-group.stories.js +++ b/src/components/form-group/form-group.stories.js @@ -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'; @@ -11,20 +11,22 @@ export default { }; export const WithSingleChildren = () => { + const description = text('Description', 'helper text'); const label = text('Label', 'Your name'); return ( - + ); }; export const WithMultipleChildren = () => { + const description = text('Description', 'helper text'); const label = text('Label', 'Options'); let value = 'option-1'; const onChange = () => {}; return ( - + { ); }; + +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 ( + + + + ); +}; +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 ( + + + + ); +}; diff --git a/src/containers/lobby/lobby.js b/src/containers/lobby/lobby.js index 6bbe558..2d7d6d3 100644 --- a/src/containers/lobby/lobby.js +++ b/src/containers/lobby/lobby.js @@ -56,6 +56,7 @@ function Lobby({ } const shareIcon = navigator.share ? 'share-alt' : 'clone'; + const shareDescription = navigator.share ? 'Поделиться' : 'Копировать ссылку'; return (
- +