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

feat(components):Light version IconSwitch and DateTimePicker #1582

Merged
merged 19 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0cf0682
feat(iconswitch): IconSwitch light version
cgirani Sep 8, 2020
94fb1b1
feat(datetimepicker): DateTimePicker light version
cgirani Sep 8, 2020
86af52a
fix(datetimepicker): use id as a preset selector
cgirani Sep 8, 2020
315f655
fix(datetimepicker): fix offset and tests updates
cgirani Sep 8, 2020
a258bd2
Merge branch 'master' into light-version-components
cgirani Sep 8, 2020
d0ef7d4
Merge branch 'master' into light-version-components
cgirani Sep 9, 2020
cb958d2
fix(datetimepicker): update class name from feedback
cgirani Sep 9, 2020
723c269
Merge branch 'light-version-components' of https://github.com/carbon-…
cgirani Sep 9, 2020
68b21ae
Merge branch 'master' into light-version-components
tay1orjones Sep 17, 2020
d71094e
Merge branch 'master' into light-version-components
tay1orjones Sep 21, 2020
1e77f20
Merge branch 'master' into light-version-components
tay1orjones Sep 23, 2020
456b415
Merge branch 'light-version-components' of github.com:IBM/carbon-addo…
davidicus Oct 8, 2020
9db4fba
feat(datetimepicker): check for legacy offset
davidicus Oct 8, 2020
f2795c8
Merge branch 'master' into light-version-components
davidicus Oct 8, 2020
ad7b32c
fix(datetimepicker): make vars uniform
davidicus Oct 8, 2020
830a480
Merge branch 'light-version-components' of github.com:IBM/carbon-addo…
davidicus Oct 8, 2020
54c0402
fix(datetimepicker): change syntax from code review
davidicus Oct 8, 2020
c168fe6
feat(datetimepicker): add legacy value in spot missed
davidicus Oct 8, 2020
c5c2adb
feat(datetimepicker): add test to cover when no id for preset
davidicus Oct 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/components/DateTimePicker/DateTimePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ export const PICKER_KINDS = {

export const PRESET_VALUES = [
{
id: 'item-01',
label: 'Last 30 minutes',
offset: 30,
},
{
id: 'item-02',
label: 'Last 1 hour',
offset: 60,
},
{
id: 'item-03',
label: 'Last 6 hours',
offset: 360,
},
{
id: 'item-04',
label: 'Last 12 hours',
offset: 720,
},
{
id: 'item-05',
label: 'Last 24 hours',
offset: 1440,
},
Expand All @@ -72,6 +77,7 @@ const propTypes = {
PropTypes.exact({
timeRangeKind: PropTypes.oneOf([PICKER_KINDS.PRESET]).isRequired,
timeRangeValue: PropTypes.exact({
id: PropTypes.string,
label: PropTypes.string.isRequired,
offset: PropTypes.number.isRequired,
}).isRequired,
Expand Down Expand Up @@ -156,6 +162,8 @@ const propTypes = {
cancelBtnLabel: PropTypes.string,
backBtnLabel: PropTypes.string,
}),
/** Light version */
light: PropTypes.bool,
};

const defaultProps = {
Expand Down Expand Up @@ -231,6 +239,7 @@ const defaultProps = {
cancelBtnLabel: 'Cancel',
backBtnLabel: 'Back',
},
light: false,
};

const DateTimePicker = ({
Expand All @@ -247,6 +256,7 @@ const DateTimePicker = ({
onCancel,
onApply,
i18n,
light,
...others
}) => {
const strings = {
Expand Down Expand Up @@ -275,6 +285,7 @@ const DateTimePicker = ({
const dateTimePickerBaseValue = {
kind: '',
preset: {
id: presets[0].id,
label: presets[0].label,
offset: presets[0].offset,
},
Expand Down Expand Up @@ -404,7 +415,15 @@ const DateTimePicker = ({
value.kind = customRangeKind;
} else {
const preset = presets
.filter(p => p.offset === (clickedPreset ? clickedPreset.offset : selectedPreset))
.filter(p => {
let filteredPreset;
if (p.id) {
filteredPreset = p.id === (clickedPreset ? clickedPreset.id : selectedPreset);
} else {
filteredPreset = p.offset === (clickedPreset ? clickedPreset.offset : selectedPreset);
}
return filteredPreset;
})
.pop();
value.preset = preset;
value.kind = PICKER_KINDS.PRESET;
Expand Down Expand Up @@ -476,7 +495,7 @@ const DateTimePicker = ({
};

const onPresetClick = preset => {
setSelectedPreset(preset.offset);
setSelectedPreset(preset.id ?? preset.offset);
renderValue(preset);
};

Expand Down Expand Up @@ -548,7 +567,7 @@ const DateTimePicker = ({
// If value was changed reset when going back to Preset
if (absoluteValue.startDate !== '' || relativeValue.lastNumber > 0) {
if (selectedPreset) {
onPresetClick(presets.filter(x => x.offset === selectedPreset)[0]);
onPresetClick(presets.filter(p => p.id ?? p.offset === selectedPreset)[0]);
resetAbsoluteValue();
resetRelativeValue();
} else {
Expand Down Expand Up @@ -665,7 +684,11 @@ const DateTimePicker = ({
id={`${iotPrefix}--date-time-picker__wrapper`}
className={`${iotPrefix}--date-time-picker__wrapper`}
>
<div className={`${iotPrefix}--date-time-picker__box`}>
<div
className={`${iotPrefix}--date-time-picker__box ${
light ? `${iotPrefix}--date-time-picker__box--light` : ''
}`}
>
<div
className={`${iotPrefix}--date-time-picker__field`}
role="button"
Expand Down Expand Up @@ -721,7 +744,7 @@ const DateTimePicker = ({
`${iotPrefix}--date-time-picker__listitem ${iotPrefix}--date-time-picker__listitem--preset`,
{
[`${iotPrefix}--date-time-picker__listitem--preset-selected`]:
selectedPreset === preset.offset,
selectedPreset === (preset.id ?? preset.offset),
}
)}
>
Expand Down
18 changes: 18 additions & 0 deletions src/components/DateTimePicker/DateTimePicker.story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,22 @@ storiesOf('Watson IoT Experimental/DateTime Picker', module)
/>
</div>
);
})
.add('Light version', () => {
const size = select('size', Object.keys(CARD_SIZES), CARD_SIZES.MEDIUMWIDE);
return (
<div style={{ width: `${getCardMinSize('lg', size).x}px`, margin: spacing06 }}>
<DateTimePicker
dateTimeMask={text('dateTimeMask', 'YYYY-MM-DD HH:mm')}
relatives={[
{
label: 'Yesterday',
value: RELATIVE_VALUES.YESTERDAY,
},
]}
light
hasTimeInput={boolean('hasTimeInput', true)}
/>
</div>
);
});
21 changes: 20 additions & 1 deletion src/components/DateTimePicker/DateTimePicker.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ describe('DateTimePicker', () => {
mount(
<DateTimePicker
{...dateTimePickerProps}
presets={[
{
label: 'Last 30 minutes',
offset: 30,
},
{
label: 'Last 1 hour',
offset: 60,
},
]}
defaultValue={{
timeRangeKind: PICKER_KINDS.PRESET,
timeRangeValue: PRESET_VALUES[1],
// test not having id
timeRangeValue: {
label: 'Last 30 minutes',
offset: 30,
},
}}
/>
);
Expand Down Expand Up @@ -427,22 +441,27 @@ describe('DateTimePicker', () => {

const presets = [
{
id: 'item-01',
label: 'last-30-min',
offset: 30,
},
{
id: 'item-02',
label: 'last-1-hour',
offset: 60,
},
{
id: 'item-03',
label: 'last-6-hour',
offset: 360,
},
{
id: 'item-04',
label: 'last-12-hour',
offset: 720,
},
{
id: 'item-05',
label: 'last-24-hour',
offset: 1440,
},
Expand Down
Loading