-
Notifications
You must be signed in to change notification settings - Fork 9
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
861 - The component does not have a red border #862
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,99 @@ | ||
import { action } from '@storybook/addon-actions' | ||
import { boolean, text } from '@storybook/addon-knobs' | ||
import React from 'react' | ||
import { boolean, object, text } from '@storybook/addon-knobs' | ||
import React, { useState } from 'react' | ||
import { ReferenceMonth } from '../MonthPicker' | ||
import { MonthRangePicker } from './MonthRangePicker' | ||
import { DateRange } from '../DateRangePicker' | ||
import { MonthRangePicker, ReferenceMonthRange } from './MonthRangePicker' | ||
|
||
const start: ReferenceMonth = { month: 5, year: 2020 } | ||
const end: ReferenceMonth = { month: 1, year: 2021 } | ||
const range = { start: start, end: end } | ||
const initialValue: ReferenceMonthRange = { start: start, end: end } | ||
|
||
const minMonth: ReferenceMonth = { month: 0, year: 2020 } | ||
const maxMonth: ReferenceMonth = { month: 3, year: 2021 } | ||
|
||
export default { | ||
title: 'Components/MonthRangePicker', | ||
} | ||
|
||
export const Default = () => ( | ||
<MonthRangePicker | ||
label={text('label', 'Month Field')} | ||
error={text('error', '')} | ||
onChange={action('changed')} | ||
inline={boolean('inline', false)} | ||
required={boolean('required', false)} | ||
disabled={boolean('disabled', false)} | ||
value={range} | ||
/> | ||
) | ||
|
||
export const MinMax = () => ( | ||
<MonthRangePicker | ||
label={text('label', 'Month Field')} | ||
error={text('error', '')} | ||
onChange={action('changed')} | ||
disabled={boolean('disabled', false)} | ||
value={range} | ||
minMonth={{ month: 0, year: 2020 }} | ||
maxMonth={{ month: 3, year: 2021 }} | ||
/> | ||
) | ||
export const Default = () => { | ||
const [range, setRange] = useState<ReferenceMonthRange>(initialValue) | ||
|
||
const handleChange = (dateRange: DateRange) => { | ||
const { startDate, endDate } = dateRange | ||
|
||
if (startDate && endDate) { | ||
setRange({ | ||
start: { month: startDate.getMonth(), year: startDate.getFullYear() }, | ||
end: { month: endDate.getMonth(), year: endDate.getFullYear() }, | ||
}) | ||
} else if (startDate) { | ||
setRange({ | ||
start: { month: startDate.getMonth(), year: startDate.getFullYear() }, | ||
end: undefined, | ||
}) | ||
} else if (endDate) { | ||
setRange({ | ||
start: undefined, | ||
end: { month: endDate.getMonth(), year: endDate.getFullYear() }, | ||
}) | ||
} else { | ||
setRange({ start: undefined, end: undefined }) | ||
} | ||
|
||
action('changed')(dateRange) | ||
} | ||
|
||
return ( | ||
<MonthRangePicker | ||
label={text('label', 'Month Field')} | ||
error={text('error', '')} | ||
onChange={handleChange} | ||
inline={boolean('inline', false)} | ||
required={boolean('required', false)} | ||
disabled={boolean('disabled', false)} | ||
value={range} | ||
/> | ||
) | ||
} | ||
|
||
export const MinMax = () => { | ||
const [range, setRange] = useState<ReferenceMonthRange>(initialValue) | ||
|
||
const handleChange = (dateRange: DateRange) => { | ||
const { startDate, endDate } = dateRange | ||
|
||
if (startDate && endDate) { | ||
setRange({ | ||
start: { month: startDate.getMonth(), year: startDate.getFullYear() }, | ||
end: { month: endDate.getMonth(), year: endDate.getFullYear() }, | ||
}) | ||
} else if (startDate) { | ||
setRange({ | ||
start: { month: startDate.getMonth(), year: startDate.getFullYear() }, | ||
end: undefined, | ||
}) | ||
} else if (endDate) { | ||
setRange({ | ||
start: undefined, | ||
end: { month: endDate.getMonth(), year: endDate.getFullYear() }, | ||
}) | ||
} else { | ||
setRange({ start: undefined, end: undefined }) | ||
} | ||
|
||
action('changed')(dateRange) | ||
} | ||
|
||
return ( | ||
<MonthRangePicker | ||
label={text('label', 'Month Field')} | ||
error={text('error', '')} | ||
onChange={handleChange} | ||
disabled={boolean('disabled', false)} | ||
value={range} | ||
minMonth={object('minMonth', minMonth)} | ||
maxMonth={object('maxMonth', maxMonth)} | ||
/> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ export function MonthRangePickerInput(props: MonthRangePickerInputProps) { | |
|
||
return ( | ||
<FormControl {...getFormControlProps()}> | ||
<BaseMonthRangeInput {...inputProps} {...rest} /> | ||
<BaseMonthRangeInput invalid={inputProps['aria-invalid']} {...inputProps} {...rest} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the aria-invalid property need to remain in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a hook's result and this hook is used everywhere, so i think it's not a good idea to remove from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I meant to just stop passing it to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, now i understand hehe |
||
</FormControl> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could declare this function at the file scope and reuse it within the component scope