Skip to content

Commit

Permalink
fix(fields): normalize sizes in DatePicker & DateRangePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Dec 21, 2022
1 parent 10a581d commit b76c78e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .storybook/components/GlobalDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CustomGlobalStyle: any = createGlobalStyle`
body.sb-show-main.sb-main-padded {
height: 100%;
padding: 0;
width: 100%;
width: 640px;
}
code {
Expand Down
4 changes: 2 additions & 2 deletions src/elements/IconBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const IconBox = styled.div<IconBoxProps>`
> svg {
display: block;
height: ${p => p.$size ?? 16}px;
width: ${p => p.$size ?? 16}px;
height: ${p => p.$size ?? 20}px;
width: ${p => p.$size ?? 20}px;
}
`
2 changes: 1 addition & 1 deletion src/elements/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export const Label = styled.label<{
display: ${p => (p.isHidden ? 'none' : 'table')};
font-size: 13px;
line-height: 1.4;
margin-bottom: 8px;
margin-bottom: 4px;
`
23 changes: 18 additions & 5 deletions src/fields/DatePicker/CalendarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export const Box = styled.div`
}
.rs-picker-date-menu {
border: solid 1px ${p => p.theme.color.lightGray};
box-shadow: inset 0px 0px 0px 1px ${p => p.theme.color.lightGray};
border-radius: 0;
margin-top: 4px;
margin-top: 2px;
.rs-picker-date-header,
.rs-calendar-header-time-toolbar,
Expand Down Expand Up @@ -187,20 +187,33 @@ export const Box = styled.div`
border: 0;
margin-top: 3px;
.rs-calendar-month-dropdown-year {
color: ${p => p.theme.color.slateGray};
&.rs-calendar-month-dropdown-year-active {
color: ${p => p.theme.color.blueYonder[100]};
}
}
.rs-calendar-month-dropdown-cell {
.rs-calendar-month-dropdown-cell-content {
> .rs-calendar-month-dropdown-cell-content {
border-radius: 0 !important;
color: ${p => p.theme.color.gunMetal};
display: inline-flex;
height: 33px;
justify-content: center;
line-height: 1;
padding: 7px 0 0;
padding: 8px 0 0;
width: 33px;
}
&:hover .rs-calendar-month-dropdown-cell-content {
&:hover > .rs-calendar-month-dropdown-cell-content {
background-color: ${p => p.theme.color.blueYonder[25]};
color: ${p => p.theme.color.blueYonder[100]};
}
&.rs-calendar-month-dropdown-cell-active > .rs-calendar-month-dropdown-cell-content {
background-color: ${p => p.theme.color.blueGray[100]};
color: ${p => p.theme.color.white};
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/fields/DateRangePicker/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function DateInputWithRef(
<Box
ref={boxRef}
$hasError={hasFormatError || hasValidationError}
$isCompact={isCompact}
$isDisabled={disabled}
$isFocused={isForcedFocused || isFocused}
$isLight={isLight}
Expand Down Expand Up @@ -194,6 +195,7 @@ export const DateInput = forwardRef(DateInputWithRef)

const Box = styled.div<{
$hasError: boolean
$isCompact: boolean
$isDisabled: boolean
$isFocused: boolean
$isLight: boolean
Expand All @@ -208,7 +210,7 @@ const Box = styled.div<{
display: inline-flex;
font-size: inherit;
justify-content: space-between;
padding: 5px 8px 7px;
padding: ${p => (p.$isCompact ? '4.5px 8px 7px' : '3px 8px 5px')};
user-select: none;
:hover {
Expand All @@ -225,6 +227,6 @@ const Box = styled.div<{
}
> div:nth-child(2) {
margin: 1px 0 0 32px;
margin: 2px 0 0 16px;
}
`
2 changes: 1 addition & 1 deletion src/fields/DateRangePicker/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const StyledNumberInput = styled.input<{
padding: 0;
text-align: center;
/* 1 digit = 8px */
width: ${p => p.$size * 0.5}rem;
width: ${p => p.$size * 8}px;
::placeholder {
color: ${p => (p.$isLight ? p.theme.color.slateGray : p.theme.color.slateGray)};
Expand Down
23 changes: 18 additions & 5 deletions src/fields/DateRangePicker/RangeCalendarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const Box = styled.div`
}
.rs-picker-daterange-menu {
border: solid 1px ${p => p.theme.color.lightGray};
box-shadow: inset 0px 0px 0px 1px ${p => p.theme.color.lightGray};
border-radius: 0;
margin-top: 4px;
margin-top: 2px;
.rs-picker-daterange-header,
.rs-calendar-header-time-toolbar,
Expand Down Expand Up @@ -208,20 +208,33 @@ const Box = styled.div`
border: 0;
margin-top: 3px;
.rs-calendar-month-dropdown-year {
color: ${p => p.theme.color.slateGray};
&.rs-calendar-month-dropdown-year-active {
color: ${p => p.theme.color.blueYonder[100]};
}
}
.rs-calendar-month-dropdown-cell {
.rs-calendar-month-dropdown-cell-content {
> .rs-calendar-month-dropdown-cell-content {
border-radius: 0 !important;
color: ${p => p.theme.color.gunMetal};
display: inline-flex;
height: 33px;
justify-content: center;
line-height: 1;
padding: 7px 0 0;
padding: 8px 0 0;
width: 33px;
}
&:hover .rs-calendar-month-dropdown-cell-content {
&:hover > .rs-calendar-month-dropdown-cell-content {
background-color: ${p => p.theme.color.blueYonder[25]};
color: ${p => p.theme.color.blueYonder[100]};
}
&.rs-calendar-month-dropdown-cell-active > .rs-calendar-month-dropdown-cell-content {
background-color: ${p => p.theme.color.blueGray[100]};
color: ${p => p.theme.color.white};
}
}
}
}
Expand Down
37 changes: 30 additions & 7 deletions src/fields/DateRangePicker/RangedTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@ type RangedTimePickerProps = {
onChange: (nextTimeTuple: TimeTuple) => Promisable<void>
}
export function RangedTimePicker({ filter, minutesRange, onChange }: RangedTimePickerProps) {
const [selectedOptionIndex, setSelectedOptionIndex] = useState(0)

const rangedTimeOptions = useMemo(() => getRangedTimeOptions(minutesRange), [minutesRange])
const filteredRangedTimeOptions = useMemo(
() => rangedTimeOptions.filter(({ label }) => filter.test(label)),
[filter, rangedTimeOptions]
)

const [selectedOptionIndex, setSelectedOptionIndex] = useState(0)
const spannedLabels = useMemo(
() =>
filteredRangedTimeOptions.map(({ label }) => {
const [hours, minutes] = label.split(':')

return (
<>
{' '}
<span>{hours}</span>:<span>{minutes}</span>
</>
)
}),
[filteredRangedTimeOptions]
)

const handleBoxKeyDown = useCallback(
(event: globalThis.KeyboardEvent) => {
Expand Down Expand Up @@ -88,25 +103,27 @@ export function RangedTimePicker({ filter, minutesRange, onChange }: RangedTimeP
role="option"
tabIndex={-1}
>
{label}
{spannedLabels[index]}
</Option>
))}
</Box>
)
}

const Box = styled.div`
background-color: ${p => p.theme.color.gainsboro};
background-color: ${p => p.theme.color.white};
box-shadow: inset 0px 0px 0px 1px ${p => p.theme.color.lightGray};
display: flex;
flex-direction: column;
left: -1px;
left: 0;
max-height: 160px;
overflow: auto;
position: absolute;
/* Non-WebKit Firefox Compatibility */
scrollbar-color: ${p => p.theme.color.lightGray};
scrollbar-width: thin;
top: 36px;
top: 32px;
width: 100%;
z-index: 9999;
::-webkit-scrollbar {
Expand All @@ -128,12 +145,18 @@ const Option = styled.div<{
isSelected: boolean
}>`
background-color: ${p => (p.isSelected ? p.theme.color.blueGray[100] : 'transparent')};
color: ${p => (p.isSelected ? p.theme.color.white : p.theme.color.gunMetal)};
cursor: pointer;
line-height: 1;
padding: 5px 9px 7px 8px;
text-align: center;
padding: 5px 0 7px 6.5px;
:hover {
background-color: ${p => (p.isSelected ? p.theme.color.blueGray[100] : p.theme.color.blueYonder[25])};
}
> span {
display: inline-flex;
justify-content: center;
width: 16px;
}
`
6 changes: 4 additions & 2 deletions src/fields/DateRangePicker/TimeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function TimeInputWithRef(
<Box
ref={boxRef}
$hasError={hasFormatError || hasValidationError}
$isCompact={isCompact}
$isDisabled={disabled}
$isFocused={isFocused}
$isLight={isLight}
Expand Down Expand Up @@ -236,6 +237,7 @@ export const TimeInput = forwardRef(TimeInputWithRef)

const Box = styled.div<{
$hasError: boolean
$isCompact: boolean
$isDisabled: boolean
$isFocused: boolean
$isLight: boolean
Expand All @@ -248,7 +250,7 @@ const Box = styled.div<{
color: ${p => (p.$isFocused ? p.theme.color.blueGray[100] : p.theme.color.slateGray)};
display: inline-block;
font-size: inherit;
padding: 5px 8px 7px;
padding: ${p => (p.$isCompact ? '4.5px 8px 7px' : '3px 8px 5px')};
position: relative;
user-select: none;
Expand All @@ -272,6 +274,6 @@ const InputGroup = styled.div`
justify-content: space-between;
> div:nth-child(2) {
margin: 1px 0 0 32px;
margin: 2px 0 0 16px;
}
`

0 comments on commit b76c78e

Please sign in to comment.