Skip to content

Commit

Permalink
feat: add required prop to date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
farhanlatheef committed Oct 24, 2023
1 parent ff8fe4e commit b3d63e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/DatePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const DatePicker = forwardRef(
defaultValue,
value,
labelProps,
required = false,
...otherProps
},
ref
Expand All @@ -63,7 +64,11 @@ const DatePicker = forwardRef(

return (
<div className="neeto-ui-input__wrapper">
{label && <Label {...labelProps}>{label}</Label>}
{label && (
<Label required={required} {...labelProps}>
{label}
</Label>
)}
<Component
data-cy={label ? `${hyphenize(label)}-input` : "picker-input"}
defaultValue={convertToDayjsObjects(defaultValue)}
Expand Down Expand Up @@ -179,6 +184,10 @@ DatePicker.propTypes = {
* To specify the default values to be displayed inside the DatePicker.
*/
defaultValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
/**
* To specify whether the Date picker is required or not.
*/
required: PropTypes.bool,
};

export default DatePicker;
11 changes: 11 additions & 0 deletions stories/Components/DateInput.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ DateInput.args = {
showTime: false,
};

const RequiredDatePicker = args => <DatePicker {...args} />;
DateInput.args = {
label: "Required Date",
type: "date",
picker: "date",
showTime: false,
required: true
};
DateInput.storyName = "Required Date";

const DatePickerWithRef = args => {
const ref = React.useRef();
const [open, setOpen] = React.useState(false);
Expand Down Expand Up @@ -209,6 +219,7 @@ export {
DateRangePicker,
DateRangePickerWithPresetRanges,
ShowTime,
RequiredDatePicker
};

export default metadata;

0 comments on commit b3d63e9

Please sign in to comment.