Skip to content

Commit

Permalink
chore(date_picker_range): add a VRT for the full width variant
Browse files Browse the repository at this point in the history
  • Loading branch information
weronikaolejniczak committed Nov 28, 2024
1 parent b937ece commit 456735c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 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.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ const meta: Meta<EuiDatePickerRangeProps> = {
export default meta;
type Story = StoryObj<EuiDatePickerRangeProps>;

const StatefulPlayground = ({
startDateControl,
endDateControl,
...rest
}: EuiDatePickerRangeProps) => {
const [selectedStartDate, setSelectedStartDate] = useState<moment.Moment>(
startDateControl.props.selected
);
const [selectedEndDate, setSelectedEndDate] = useState<moment.Moment>(
endDateControl.props.selected
);

const startControl = React.cloneElement(startDateControl, {
selected: selectedStartDate,
onChange: setSelectedStartDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});

const endControl = React.cloneElement(endDateControl, {
selected: selectedEndDate,
onChange: setSelectedEndDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});

return (
<EuiDatePickerRange
startDateControl={startControl}
endDateControl={endControl}
{...rest}
/>
);
};

export const Playground: Story = {
parameters: {
controls: {
Expand Down Expand Up @@ -104,37 +139,16 @@ export const RestrictedSelection: Story = {
render: (args) => <StatefulPlayground {...args} />,
};

const StatefulPlayground = ({
startDateControl,
endDateControl,
...rest
}: EuiDatePickerRangeProps) => {
const [selectedStartDate, setSelectedStartDate] = useState<moment.Moment>(
startDateControl.props.selected
);
const [selectedEndDate, setSelectedEndDate] = useState<moment.Moment>(
endDateControl.props.selected
);

const startControl = React.cloneElement(startDateControl, {
selected: selectedStartDate,
onChange: setSelectedStartDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});

const endControl = React.cloneElement(endDateControl, {
selected: selectedEndDate,
onChange: setSelectedEndDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});
/**
* VRT only stories
*/

return (
<EuiDatePickerRange
startDateControl={startControl}
endDateControl={endControl}
{...rest}
/>
);
export const FullWidth: Story = {
tags: ['vrt-only'],
args: {
startDateControl: <EuiDatePicker />,
endDateControl: <EuiDatePicker />,
fullWidth: true,
},
render: (args) => <StatefulPlayground {...args} />,
};

0 comments on commit 456735c

Please sign in to comment.