Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove clearable from color and time pickers #1965

Merged
merged 10 commits into from
Apr 30, 2024
7 changes: 7 additions & 0 deletions .changeset/light-ligers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin-date-time": major
---

Remove the `clearable` prop and add a `required` prop to `DateRangePicker`, `DateTimePicker`, `TimePicker` and `TimeRangePicker`

The clear button will automatically be shown for all optional fields.
7 changes: 7 additions & 0 deletions .changeset/ninety-adults-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin-color-picker": major
---

Remove `clearable` prop and add a `required` prop to `ColorPicker`

The clear button will automatically be shown for all optional fields.
7 changes: 4 additions & 3 deletions packages/admin/admin-color-picker/src/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface ColorPickerProps extends Omit<InputWithPopperProps, "children"
startAdornment?: InputBaseProps["startAdornment"];
endAdornment?: InputBaseProps["endAdornment"];
invalidIndicatorCharacter?: string;
clearable?: boolean;
required?: boolean;
titleText?: React.ReactNode;
clearButtonText?: React.ReactNode;
components?: ColorPickerPropsComponents;
Expand All @@ -78,7 +78,7 @@ export const ColorPicker = (inProps: ColorPickerProps) => {
startAdornment,
endAdornment,
onBlur,
clearable,
required,
titleText = <FormattedMessage id="comet.colorPicker.title" defaultMessage="Choose a color" />,
clearButtonText = <FormattedMessage id="comet.colorPicker.clearButton" defaultMessage="clear color" />,
components = {},
Expand Down Expand Up @@ -122,6 +122,7 @@ export const ColorPicker = (inProps: ColorPickerProps) => {

return (
<Root
required={required}
startAdornment={
startAdornment ? (
startAdornment
Expand Down Expand Up @@ -149,7 +150,7 @@ export const ColorPicker = (inProps: ColorPickerProps) => {
)
}
endAdornment={
clearable ? (
!required ? (
<>
<ClearInputAdornment position="end" hasClearableContent={Boolean(value)} onClick={() => onChange?.(undefined)} />
{endAdornment}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DateRangePickerProps extends Omit<InputWithPopperProps, "childr
value?: DateRange;
formatDateOptions?: FormatDateOptions;
rangeStringSeparator?: string;
clearable?: boolean;
required?: boolean;
monthsToShow?: number;
maxDate?: Date;
minDate?: Date;
Expand Down Expand Up @@ -77,7 +77,7 @@ export const DateRangePicker = (inProps: DateRangePickerProps) => {
formatDateOptions,
rangeStringSeparator = " — ",
endAdornment,
clearable,
required,
placeholder,
monthsToShow = 2,
minDate = defaultMinDate,
Expand All @@ -101,8 +101,9 @@ export const DateRangePicker = (inProps: DateRangePickerProps) => {
{...slotProps?.root}
{...inputWithPopperProps}
readOnly
required={required}
endAdornment={
clearable ? (
!required ? (
<>
<ClearInputAdornment position="end" hasClearableContent={Boolean(value)} onClick={() => onChange && onChange(undefined)} />
{endAdornment}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export interface DateTimePickerProps
}> {
onChange?: (value?: Date) => void;
value?: Date;
clearable?: boolean;
required?: boolean;
}

export const DateTimePicker = (inProps: DateTimePickerProps) => {
const { onChange, value, slotProps, clearable, ...restProps } = useThemeProps({
const { onChange, value, required, slotProps, ...restProps } = useThemeProps({
props: inProps,
name: "CometAdminDateTimePicker",
});
Expand Down Expand Up @@ -106,6 +106,7 @@ export const DateTimePicker = (inProps: DateTimePickerProps) => {
value={value ? getIsoDateString(value) : undefined}
onChange={onChangeDate}
fullWidth
required={required}
{...slotProps?.datePicker}
/>
</DateFormControl>
Expand All @@ -116,7 +117,7 @@ export const DateTimePicker = (inProps: DateTimePickerProps) => {
placeholder={intl.formatMessage({ id: "comet.timeTimePicker.time", defaultMessage: "Time" })}
onChange={onChangeTime}
fullWidth
clearable={clearable}
required={required}
{...slotProps?.timePicker}
/>
</TimeFormControl>
Expand Down
7 changes: 4 additions & 3 deletions packages/admin/admin-date-time/src/timePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface TimePickerProps extends Omit<InputWithPopperProps, "children" |
minuteStep?: number;
min?: string;
max?: string;
clearable?: boolean;
required?: boolean;
slotProps?: SlotProps;
}

Expand All @@ -65,7 +65,7 @@ export const TimePicker = (inProps: TimePickerProps) => {
value,
formatOptions,
endAdornment,
clearable,
required,
minuteStep = 15,
placeholder,
min = "00:00",
Expand Down Expand Up @@ -118,8 +118,9 @@ export const TimePicker = (inProps: TimePickerProps) => {
inputWithPopperProps.onOpenPopper?.();
}}
readOnly
required={required}
endAdornment={
clearable ? (
!required ? (
<>
<ClearInputAdornment position="end" hasClearableContent={Boolean(value)} onClick={() => onChange?.(undefined)} />
{endAdornment}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface TimeRangePickerProps
minuteStep?: number;
min?: string;
max?: string;
clearable?: boolean;
required?: boolean;
separatorText?: React.ReactNode;
}

Expand All @@ -90,6 +90,7 @@ export const TimeRangePicker = (inProps: TimeRangePickerProps) => {
separatorText = <FormattedMessage id="comet.dateTime.fromToSeparatorText" defaultMessage="to" />,
className,
sx,
required,
slotProps,
...propsForBothTimePickers
} = useThemeProps({ props: inProps, name: "CometAdminTimeRangePicker" });
Expand Down Expand Up @@ -153,6 +154,7 @@ export const TimeRangePicker = (inProps: TimeRangePickerProps) => {
onOpenPopper={() => setStartPickerIsOpen(true)}
onClosePopper={() => setStartPickerIsOpen(false)}
fullWidth
required={required}
{...propsForBothTimePickers}
{...slotProps?.startTimePicker}
/>
Expand All @@ -167,6 +169,7 @@ export const TimeRangePicker = (inProps: TimeRangePickerProps) => {
onOpenPopper={() => setEndPickerIsOpen(true)}
onClosePopper={() => setEndPickerIsOpen(false)}
fullWidth
required={required}
{...propsForBothTimePickers}
{...slotProps?.endTimePicker}
/>
Expand Down
19 changes: 2 additions & 17 deletions storybook/src/admin-date-time/AllDateAndTimePickers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,24 @@ const Story = () => {
<form>
<Card>
<CardContent>
<DateField
name="date"
label="Date"
fullWidth
clearable
helperText={`Stringified value: ${JSON.stringify(values.date)}`}
/>
<DateField name="date" label="Date" fullWidth helperText={`Stringified value: ${JSON.stringify(values.date)}`} />
<DateRangeField
name="dateRange"
label="DateRange"
fullWidth
clearable
helperText={`Stringified value: ${JSON.stringify(values.dateRange)}`}
/>
<DateTimeField
name="dateTime"
label="DateTime"
fullWidth
clearable
helperText={`Stringified value: ${JSON.stringify(values.dateTime)}`}
/>
<TimeField
name="time"
label="Time"
fullWidth
clearable
helperText={`Stringified value: ${JSON.stringify(values.time)}`}
/>
<TimeField name="time" label="Time" fullWidth helperText={`Stringified value: ${JSON.stringify(values.time)}`} />
<TimeRangeField
name="timeRange"
label="TimeRange"
fullWidth
clearable
helperText={`Stringified value: ${JSON.stringify(values.timeRange)}`}
/>
</CardContent>
Expand Down
2 changes: 1 addition & 1 deletion storybook/src/admin-date-time/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Story = () => {
<Card>
<CardContent>
<Field name="dateRangeOne" label="Date range" fullWidth component={FinalFormDateRangePicker} />
<Field name="dateRangeTwo" label="Clearable" fullWidth clearable component={FinalFormDateRangePicker} />
<Field name="dateRangeTwo" label="Required" fullWidth required component={FinalFormDateRangePicker} />
</CardContent>
</Card>
<pre>{JSON.stringify(values, null, 4)}</pre>
Expand Down
2 changes: 1 addition & 1 deletion storybook/src/admin-date-time/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Story = () => {
<Card>
<CardContent>
<Field name="dateTimeOne" label="Date-Time" fullWidth component={FinalFormDateTimePicker} />
<Field name="dateTimeTwo" label="Clearable Date-Time" fullWidth clearable component={FinalFormDateTimePicker} />
<Field name="dateTimeTwo" label="Required" fullWidth required component={FinalFormDateTimePicker} />
</CardContent>
</Card>
<pre>{JSON.stringify(values, null, 4)}</pre>
Expand Down
2 changes: 1 addition & 1 deletion storybook/src/admin-date-time/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Story = () => {
<Card>
<CardContent>
<Field name="timeOne" label="Time" fullWidth component={FinalFormTimePicker} />
<Field name="timeTwo" label="Clearable" fullWidth clearable component={FinalFormTimePicker} />
<Field name="timeTwo" label="Required" fullWidth required component={FinalFormTimePicker} />
</CardContent>
</Card>
<pre>{JSON.stringify(values, null, 4)}</pre>
Expand Down
2 changes: 1 addition & 1 deletion storybook/src/admin-date-time/TimeRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Story = () => {
<Card>
<CardContent>
<Field name="timeRangeOne" label="Time range" fullWidth component={FinalFormTimeRangePicker} />
<Field name="timeRangeTwo" label="Clearable" fullWidth clearable component={FinalFormTimeRangePicker} />
<Field name="timeRangeTwo" label="Required" fullWidth required component={FinalFormTimeRangePicker} />
</CardContent>
</Card>
<pre>{JSON.stringify(values, null, 4)}</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ storiesOf("stories/components/Color Picker/Color Picker", module).add("Color Pic
const [colorTwo, setColorTwo] = React.useState<string | undefined>("rgba(255, 127, 80, 0.75)");
const [colorThree, setColorThree] = React.useState<string | undefined>();
const [colorFour, setColorFour] = React.useState<string | undefined>();
const [colorFive, setColorFive] = React.useState<string | undefined>();

return (
<Grid container spacing={4} sx={{ pb: 2 }}>
Expand Down Expand Up @@ -56,6 +57,11 @@ storiesOf("stories/components/Color Picker/Color Picker", module).add("Color Pic
<ColorPicker fullWidth disabled value={colorFour} onChange={setColorFour} />
</FieldContainer>
</Grid>
<Grid item md={3}>
<FieldContainer label="Required" fullWidth required>
<ColorPicker fullWidth required value={colorFive} onChange={setColorFive} />
</FieldContainer>
</Grid>
</Grid>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import * as React from "react";

storiesOf("stories/components/Color Picker/Color Picker Customized", module).add("Color Picker Customized", () => {
const [colorOne, setColorOne] = React.useState<string | undefined>("#00ff00");
const [colorTwo, setColorTwo] = React.useState<string | undefined>("rgba(255, 127, 80, 0.75)");
const [colorThree, setColorThree] = React.useState<string | undefined>();
const [colorTwo, setColorTwo] = React.useState<string | undefined>();

const CustomColorPreview = ({ color }: ColorPickerColorPreviewProps): React.ReactElement => {
return <EmojiEmotions htmlColor={color} sx={{ fontSize: 24 }} />;
Expand All @@ -24,7 +23,7 @@ storiesOf("stories/components/Color Picker/Color Picker Customized", module).add

return (
<Grid container spacing={4} sx={{ pb: 2 }}>
<Grid item md={4}>
<Grid item md={6}>
<FieldContainer label="Without Picker" fullWidth>
<ColorPicker
fullWidth
Expand Down Expand Up @@ -54,17 +53,12 @@ storiesOf("stories/components/Color Picker/Color Picker Customized", module).add
/>
</FieldContainer>
</Grid>
<Grid item md={4}>
<FieldContainer label="Clearable" fullWidth>
<ColorPicker fullWidth clearable value={colorTwo} onChange={setColorTwo} colorFormat="rgba" />
</FieldContainer>
</Grid>
<Grid item md={4}>
<Grid item md={6}>
<FieldContainer label="Custom Color Preview" fullWidth>
<ColorPicker
fullWidth
value={colorThree}
onChange={setColorThree}
value={colorTwo}
onChange={setColorTwo}
components={{
ColorPickerColorPreview: CustomColorPreview,
ColorPickerInvalidPreview: CustomColorInvalidPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ storiesOf("stories/components/Color Picker/Color Picker Final Form", module).add
<Grid item md={3}>
<Field name="color4" label="Disabled" fullWidth disabled component={FinalFormColorPicker} />
</Grid>
<Grid item md={3}>
<Field name="color5" label="Required" fullWidth required component={FinalFormColorPicker} />
</Grid>
</Grid>
)}
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ storiesOf("stories/form/components/Date & Time Pickers/Date Picker", module)
</FieldContainer>
</Grid>
<Grid item xs={6} md={3}>
<FieldContainer label="Clearable" fullWidth>
<DatePicker fullWidth value={dateThree} onChange={setDateThree} />
<FieldContainer label="Required" fullWidth required>
<DatePicker fullWidth value={dateThree} onChange={setDateThree} required />
</FieldContainer>
</Grid>
<Grid item xs={6} md={3}>
Expand Down Expand Up @@ -61,7 +61,7 @@ storiesOf("stories/form/components/Date & Time Pickers/Date Picker", module)
<Field name="dateTwo" label="Show two months" fullWidth component={FinalFormDatePicker} monthsToShow={2} />
</Grid>
<Grid item xs={6} md={3}>
<Field name="dateThree" label="Clearable " fullWidth component={FinalFormDatePicker} clearable />
<Field name="dateThree" label="Required" fullWidth component={FinalFormDatePicker} required />
</Grid>
<Grid item xs={6} md={3}>
<Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ storiesOf("stories/form/components/Date & Time Pickers/Date-Range Picker", modul
</FieldContainer>
</Grid>
<Grid item xs={6} md={4}>
<FieldContainer label="Clearable" fullWidth>
<DateRangePicker fullWidth value={dateTwo} onChange={setDateTwo} clearable />
<FieldContainer label="Required" fullWidth required>
<DateRangePicker fullWidth value={dateTwo} onChange={setDateTwo} required />
</FieldContainer>
</Grid>
<Grid item xs={6} md={4}>
Expand Down Expand Up @@ -54,7 +54,7 @@ storiesOf("stories/form/components/Date & Time Pickers/Date-Range Picker", modul
<Field name="dateOne" label="Date-Range Picker" fullWidth component={FinalFormDateRangePicker} />
</Grid>
<Grid item xs={6} md={4}>
<Field name="dateTwo" label="Clearable" fullWidth component={FinalFormDateRangePicker} clearable />
<Field name="dateTwo" label="Required" fullWidth component={FinalFormDateRangePicker} required />
</Grid>
<Grid item xs={6} md={4}>
<Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ storiesOf("stories/form/components/Date & Time Pickers/Date-Time Picker", module
</FieldContainer>
</Grid>
<Grid item xs={12} md={6}>
<FieldContainer label="Clearable" fullWidth>
<DateTimePicker value={dateTimeTwo} onChange={setDateTimeTwo} clearable />
<FieldContainer label="Required" fullWidth required>
<DateTimePicker value={dateTimeTwo} onChange={setDateTimeTwo} required />
</FieldContainer>
</Grid>
<Grid item xs={12} md={6}>
Expand Down Expand Up @@ -72,7 +72,7 @@ storiesOf("stories/form/components/Date & Time Pickers/Date-Time Picker", module
<Field name="dateTimeOne" label="Date Picker" fullWidth component={FinalFormDateTimePicker} />
</Grid>
<Grid item xs={12} md={6}>
<Field name="dateTimeTwo" label="Clearable" fullWidth component={FinalFormDateTimePicker} clearable />
<Field name="dateTimeTwo" label="Required" fullWidth required component={FinalFormDateTimePicker} />
</Grid>
<Grid item xs={12} md={6}>
<Field
Expand Down
Loading
Loading