From f4e71c88544c7994191d08b3776f125b9f3c98ba Mon Sep 17 00:00:00 2001 From: Miki Date: Thu, 18 Jul 2024 11:29:30 -0700 Subject: [PATCH] Introduce compressed appearance for OuiSuperDatePicker (#1307) Also: * Sync changelog * Add compressed SuperDatePicker internal component Signed-off-by: Miki (cherry picked from commit c3c02d57349e4e1150abbc26f6cda5620de76957) Signed-off-by: Miki --- CHANGELOG.md | 6 ++++ .../super_date_picker_config.js | 12 +++++++ .../date_picker/date_picker_range.tsx | 7 ++++ .../super_date_picker.test.tsx.snap | 2 ++ .../super_update_button.test.tsx.snap | 5 +++ .../super_date_picker/_super_date_picker.scss | 9 +++++ .../date_popover/_date_popover_button.scss | 5 +++ .../date_popover/date_popover_button.tsx | 3 ++ .../super_date_picker/super_date_picker.tsx | 36 +++++++++++++++++-- .../super_date_picker/super_update_button.tsx | 5 ++- 10 files changed, 87 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47f1a7b7cf..9eb51c5026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ ### 🔩 Tests +## [`1.8.1`](https://github.com/opensearch-project/oui/tree/1.8) + +### 🐛 Bug Fixes + +- Introduce compressed appearance for OuiSuperDatePicker ([#1307](https://github.com/opensearch-project/oui/pull/1307)) + ## [`1.8.0`](https://github.com/opensearch-project/oui/tree/1.8.0) ### Deprecations diff --git a/src-docs/src/views/super_date_picker/super_date_picker_config.js b/src-docs/src/views/super_date_picker/super_date_picker_config.js index 073c704204..f8ebe832f0 100644 --- a/src-docs/src/views/super_date_picker/super_date_picker_config.js +++ b/src-docs/src/views/super_date_picker/super_date_picker_config.js @@ -23,6 +23,7 @@ export default () => { const [isLoading, setIsLoading] = useState(false); const [showUpdateButton, setShowUpdateButton] = useState(true); const [isAutoRefreshOnly, setIsAutoRefreshOnly] = useState(false); + const [compressed, setCompressed] = useState(false); const [start, setStart] = useState('now-30m'); const [end, setEnd] = useState('now'); const [isPaused, setIsPaused] = useState(true); @@ -78,6 +79,10 @@ export default () => { setIsAutoRefreshOnly(!isAutoRefreshOnly); }; + const toggleCompressed = () => { + setCompressed(!compressed); + }; + return ( { onChange={toggleDisabled} checked={isDisabled} /> +   + { recentlyUsedRanges={recentlyUsedRanges} showUpdateButton={showUpdateButton} isAutoRefreshOnly={isAutoRefreshOnly} + compressed={compressed} /> diff --git a/src/components/date_picker/date_picker_range.tsx b/src/components/date_picker/date_picker_range.tsx index 14c88755cd..5214b2db2b 100644 --- a/src/components/date_picker/date_picker_range.tsx +++ b/src/components/date_picker/date_picker_range.tsx @@ -69,6 +69,11 @@ export type OuiDatePickerRangeProps = CommonProps & { * The start date `OuiDatePicker` element */ startDateControl: ReactNode; + + /** + * when `true` creates a shorter input + */ + compressed?: boolean; }; export const OuiDatePickerRange: FunctionComponent = ({ @@ -80,6 +85,7 @@ export const OuiDatePickerRange: FunctionComponent = ({ fullWidth, isCustom, readOnly, + compressed, ...rest }) => { const classes = classNames( @@ -87,6 +93,7 @@ export const OuiDatePickerRange: FunctionComponent = ({ { 'ouiDatePickerRange--fullWidth': fullWidth, 'ouiDatePickerRange--readOnly': readOnly, + 'ouiDatePickerRange--compressed': compressed, }, className ); diff --git a/src/components/date_picker/super_date_picker/__snapshots__/super_date_picker.test.tsx.snap b/src/components/date_picker/super_date_picker/__snapshots__/super_date_picker.test.tsx.snap index 639679a9d7..d3d5987f51 100644 --- a/src/components/date_picker/super_date_picker/__snapshots__/super_date_picker.test.tsx.snap +++ b/src/components/date_picker/super_date_picker/__snapshots__/super_date_picker.test.tsx.snap @@ -9,6 +9,7 @@ exports[`OuiSuperDatePicker is rendered 1`] = ` = ( @@ -82,6 +83,7 @@ export const OuiDatePopoverButton: FunctionComponent isOpen, onPopoverToggle, onPopoverClose, + compressed, ...rest } = props; @@ -93,6 +95,7 @@ export const OuiDatePopoverButton: FunctionComponent 'ouiDatePopoverButton-isInvalid': isInvalid, 'ouiDatePopoverButton-needsUpdating': needsUpdating, 'ouiDatePopoverButton-disabled': isDisabled, + 'ouiDatePopoverButton-compressed': compressed, }, ]); diff --git a/src/components/date_picker/super_date_picker/super_date_picker.tsx b/src/components/date_picker/super_date_picker/super_date_picker.tsx index 2e475e905a..51267ddda3 100644 --- a/src/components/date_picker/super_date_picker/super_date_picker.tsx +++ b/src/components/date_picker/super_date_picker/super_date_picker.tsx @@ -144,6 +144,11 @@ export type OuiSuperDatePickerProps = CommonProps & { 'needsUpdate' | 'showTooltip' | 'isLoading' | 'isDisabled' | 'onClick' > >; + + /** + * when `true` creates a shorter input + */ + compressed?: boolean; }; interface OuiSuperDatePickerState { @@ -198,6 +203,7 @@ export class OuiSuperDatePicker extends Component< showUpdateButton: true, start: 'now-15m', timeFormat: 'HH:mm', + compressed: false, }; asyncInterval?: AsyncInterval; @@ -387,6 +393,7 @@ export class OuiSuperDatePicker extends Component< refreshInterval, timeFormat, utcOffset, + compressed, } = this.props; if (isAutoRefreshOnly) { @@ -420,6 +427,7 @@ export class OuiSuperDatePicker extends Component<