Skip to content

Commit

Permalink
fix(forms): updates Message to receive margin when intermediaries are…
Browse files Browse the repository at this point in the history
… present (#1799)
  • Loading branch information
geotrev committed May 1, 2024
1 parent e2cd75f commit 9b59a96
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
18 changes: 17 additions & 1 deletion packages/datepickers/demo/datepicker.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import README from '../README.md';
<Canvas>
<Story
name="Datepicker"
args={{ dateStyle: DATE_STYLE_OPTIONS[1], eventsEnabled: true, isAnimated: true }}
args={{
dateStyle: DATE_STYLE_OPTIONS[1],
eventsEnabled: true,
isAnimated: true,
message: 'Message'
}}
argTypes={{
value: { control: 'date' },
minValue: { control: 'date' },
Expand All @@ -25,6 +30,17 @@ import README from '../README.md';
control: 'radio',
options: DATE_STYLE_OPTIONS,
table: { category: 'Story' }
},
hasMessage: { name: 'Message', control: { type: 'boolean' }, table: 'Story' },
message: { name: 'children', control: { type: 'text' }, table: { category: 'Message' } },
validation: {
options: ['success', 'warning', 'error'],
control: { type: 'radio' },
table: { category: 'Input' }
},
validationLabel: {
control: { type: 'text' },
table: { category: 'Message' }
}
}}
parameters={{
Expand Down
27 changes: 22 additions & 5 deletions packages/datepickers/demo/stories/DatepickerStory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,44 @@
import React from 'react';
import { Story } from '@storybook/react';
import { Col, Grid, Row } from '@zendeskgarden/react-grid';
import { Field, Input, Label } from '@zendeskgarden/react-forms';
import { Field, Input, Label, Message } from '@zendeskgarden/react-forms';
import { Datepicker, IDatepickerProps } from '@zendeskgarden/react-datepickers';
import { DATE_STYLE } from './types';

interface IArgs extends IDatepickerProps {
dateStyle: DATE_STYLE;
hasMessage?: boolean;
message?: string;
validation?: 'success' | 'warning' | 'error';
validationLabel?: string;
}

export const DatepickerStory: Story<IArgs> = ({ dateStyle, isCompact, ...args }) => {
export const DatepickerStory: Story<IArgs> = ({
dateStyle,
isCompact,
hasMessage,
message,
validation,
validationLabel,
...args
}) => {
const formatDate = (date: Date) =>
new Intl.DateTimeFormat(args.locale, { dateStyle }).format(date);

return (
<Grid>
<Row style={{ height: 'calc(100vh - 80px)' }}>
<Col textAlign="center" alignSelf="center">
<Row justifyContent="center" style={{ height: 'calc(100vh - 80px)' }}>
<Col alignSelf="center">
<Field>
<Label hidden>{Datepicker.displayName}</Label>
<Datepicker {...args} formatDate={formatDate} isCompact={isCompact}>
<Input isCompact={isCompact} style={{ width: isCompact ? 256 : 320 }} />
<Input isCompact={isCompact} validation={validation} />
</Datepicker>
{hasMessage && (
<Message validation={validation} validationLabel={validationLabel}>
{message}
</Message>
)}
</Field>
</Col>
</Row>
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/styled/text/StyledTextInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const sizeStyles = (props: IStyledTextInputProps & ThemeProps<DefaultTheme>) =>
${StyledHint} + &&,
${StyledMessage} + &&,
&& + ${StyledHint},
&& + ${StyledMessage} {
&& ~ ${StyledMessage} {
margin-top: ${props.theme.space.base * (props.isCompact ? 1 : 2)}px;
}
/* stylelint-enable */
Expand Down

0 comments on commit 9b59a96

Please sign in to comment.