Skip to content

Commit

Permalink
[breaking] Separate React-Clock props from component's own props
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Apr 30, 2024
1 parent 75c20e9 commit f4924bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/react-timerange-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Displays an input field complete with custom inputs, native input and a clock.
| clearAriaLabel | `aria-label` for the clear button. | n/a | `"Clear value"` |
| clearIcon | Content of the clear button. Setting the value explicitly to `null` will hide the icon. | (default icon) | <ul><li>String: `"Clear"`</li><li>React element: `<ClearIcon />`</li><li>React function: `ClearIcon`</li></ul> |
| clockAriaLabel | `aria-label` for the clock button. | n/a | `"Toggle clock"` |
| clockClassName | Class name(s) that will be added along with `"react-clock"` to the main React-Clock `<time>` element. | n/a | <ul><li>String: `"class1 class2"`</li><li>Array of strings: `["class1", "class2 class3"]`</li></ul> |
| clockProps | Props to pass to React-Clock component. | n/a | See [React-Clock documentation](https://github.com/wojtekmaj/react-clock) |
| clockIcon | Content of the clock button. Setting the value explicitly to `null` will hide the icon. | (default icon) | <ul><li>String: `"Clock"`</li><li>React element: `<ClockIcon />`</li><li>React function: `ClockIcon`</li></ul> |
| closeClock | Whether to close the clock on value selection. **Note**: It's recommended to use `shouldCloseClock` function instead. | `true` | `false` |
| data-testid | `data-testid` attribute for the main React-TimeRange-Picker `<div>` element. | n/a | `"timerange-picker"` |
Expand Down
6 changes: 4 additions & 2 deletions packages/react-timerange-picker/src/TimeRangePicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ describe('TimeRangePicker', () => {
expect(wrapper).toHaveClass('react-timerange-picker--open');
});

it('applies clockClassName to the clock when given a string', () => {
it('applies clock className to the clock when given a string', () => {
const clockClassName = 'testClassName';

const { container } = render(<TimeRangePicker clockClassName={clockClassName} isOpen />);
const { container } = render(
<TimeRangePicker clockProps={{ className: clockClassName }} isOpen />,
);

const clock = container.querySelector('.react-clock');

Expand Down
21 changes: 5 additions & 16 deletions packages/react-timerange-picker/src/TimeRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,9 @@ export type TimeRangePickerProps = {
*/
clockAriaLabel?: string;
/**
* Class name(s) that will be added along with `"react-clock"` to the main React-Clock `<time>` element.
*
* @example 'class1 class2'
* @example ['class1', 'class2 class3']
* Props to pass to React-Clock component.
*/
clockClassName?: ClassName;
clockProps?: ClockProps;
/**
* Content of the clock button. Setting the value explicitly to `null` will hide the icon.
*
Expand Down Expand Up @@ -326,8 +323,7 @@ export type TimeRangePickerProps = {
* @example ["22:15:00", "23:45:00"]
*/
value?: LooseValue;
} & ClockProps &
Omit<EventProps, 'onChange' | 'onFocus'>;
} & Omit<EventProps, 'onChange' | 'onFocus'>;

export default function TimeRangePicker(props: TimeRangePickerProps) {
const {
Expand Down Expand Up @@ -602,21 +598,14 @@ export default function TimeRangePicker(props: TimeRangePickerProps) {
return null;
}

const {
clockClassName,
className: timeRangePickerClassName, // Unused, here to exclude it from clockProps
onChange: onChangeProps, // Unused, here to exclude it from clockProps
portalContainer,
value,
...clockProps
} = props;
const { clockProps, portalContainer, value } = props;

const className = `${baseClassName}__clock`;
const classNames = clsx(className, `${className}--${isOpen ? 'open' : 'closed'}`);

const [valueFrom] = Array.isArray(value) ? value : [value];

const clock = <Clock className={clockClassName} value={valueFrom} {...clockProps} />;
const clock = <Clock locale={locale} value={valueFrom} {...clockProps} />;

return portalContainer ? (
createPortal(
Expand Down
2 changes: 1 addition & 1 deletion test/Test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function Test() {
{...ariaLabelProps}
{...placeholderProps}
className="myCustomTimeRangePickerClassName"
clockClassName="myCustomClockClassName"
clockProps={{ className: 'myCustomClockClassName' }}
data-testid="myCustomTimeRangePicker"
disabled={disabled}
locale={locale}
Expand Down

0 comments on commit f4924bc

Please sign in to comment.