Skip to content

Commit c000d26

Browse files
authored
Merge pull request #73 from headwirecom/feature/datepicker-style
Make the style of date picker more aligned with other fields
2 parents ea484fb + 9fad4dc commit c000d26

File tree

7 files changed

+111
-14
lines changed

7 files changed

+111
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Makes the little calendar icon grey on Chrome
3+
* Otherwise it's not visible with dark mode styles
4+
*/
5+
::-webkit-calendar-picker-indicator {
6+
filter: invert(0.5);
7+
position: relative;
8+
top: 2px;
9+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2020 headwire.com, Inc
5+
https://github.com/headwirecom/jsonforms-react-spectrum-renderers
6+
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.
25+
*/
26+
import React from 'react';
27+
import './DatePicker.css';
28+
29+
/**
30+
* React Spectrum does not have date picker (it is in progress, not usable at the time of writing).
31+
* We can make the default date picker look more consistent with other React Spectrum elements by
32+
* copying the same styles as React Spectrum applies to TextField and FieldLabel.
33+
*/
34+
const inputStyle: React.CSSProperties = {
35+
border: `var(--spectrum-alias-border-size-thin,var(--spectrum-global-dimension-static-size-10)) solid`,
36+
borderRadius: `var(--spectrum-alias-border-radius-regular,var(--spectrum-global-dimension-size-50))`,
37+
boxSizing: 'border-box',
38+
padding: `3px var(--spectrum-global-dimension-size-150) 5px calc(var(--spectrum-global-dimension-size-150) - 1px)`,
39+
textIndent: `0`,
40+
width: `100%`,
41+
height: `var(--spectrum-alias-single-line-height,var(--spectrum-global-dimension-size-400))`,
42+
verticalAlign: `top`,
43+
margin: `0`,
44+
overflow: `visible`,
45+
fontFamily: `adobe-clean-ux,adobe-clean,Source Sans Pro,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif`,
46+
fontSize: `var(--spectrum-alias-font-size-default,var(--spectrum-global-dimension-font-size-100))`,
47+
lineHeight: `var(--spectrum-alias-body-text-line-height,var(--spectrum-global-font-line-height-medium))`,
48+
textOverflow: `ellipsis`,
49+
transition: `border-color .13s ease-in-out,box-shadow .13s ease-in-out`,
50+
outline: `none`,
51+
backgroundColor: `var(--spectrum-global-color-gray-50)`,
52+
borderColor: `var(--spectrum-alias-border-color,var(--spectrum-global-color-gray-400))`,
53+
color: `var(--spectrum-alias-text-color,var(--spectrum-global-color-gray-800))`,
54+
};
55+
56+
const labelStyle: React.CSSProperties = {
57+
boxSizing: 'border-box',
58+
padding: `var(--spectrum-global-dimension-size-50) 0 var(--spectrum-global-dimension-size-65)`,
59+
fontSize: `var(--spectrum-global-dimension-font-size-75)`,
60+
fontWeight: `var(--spectrum-global-font-weight-regular,400)` as React.CSSProperties['fontWeight'],
61+
lineHeight: `var(--spectrum-global-font-line-height-small,1.3)`,
62+
verticalAlign: `top`,
63+
WebkitFontSmoothing: `subpixel-antialiased`,
64+
MozOsxFontSmoothing: `auto`,
65+
cursor: `default`,
66+
};
67+
68+
export const DatePicker: React.FC<React.ComponentProps<'input'>> = (props) => {
69+
return (
70+
<input
71+
{...props}
72+
style={props.style ? { ...inputStyle, ...props.style } : inputStyle}
73+
/>
74+
);
75+
};
76+
77+
export const DatePickerLabel: React.FC<React.ComponentProps<'label'>> = (
78+
props
79+
) => {
80+
return (
81+
<label
82+
{...props}
83+
style={props.style ? { ...labelStyle, ...props.style } : labelStyle}
84+
/>
85+
);
86+
};

packages/spectrum/src/cells/DateCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ import {
3333
rankWith,
3434
} from '@jsonforms/core';
3535
import { withJsonFormsCellProps } from '@jsonforms/react';
36+
import { DatePicker } from '../additional/DatePicker';
3637

3738
export const DateCell = (props: CellProps) => {
3839
const { data, id, enabled, uischema, path, handleChange } = props;
3940

4041
return (
41-
<input
42+
<DatePicker
4243
type='date'
4344
value={data ?? ''}
4445
onChange={(ev) => handleChange(path, ev.target.value)}

packages/spectrum/src/cells/DateTimeCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
rankWith,
3434
} from '@jsonforms/core';
3535
import { withJsonFormsCellProps } from '@jsonforms/react';
36+
import { DatePicker } from '../additional/DatePicker';
3637

3738
export const DateTimeCell = (props: CellProps) => {
3839
const { data, id, enabled, uischema, path, handleChange } = props;
@@ -41,7 +42,7 @@ export const DateTimeCell = (props: CellProps) => {
4142
};
4243

4344
return (
44-
<input
45+
<DatePicker
4546
type='datetime-local'
4647
value={(data ?? '').substr(0, 16)}
4748
onChange={(ev) => handleChange(path, toISOString(ev.target.value))}

packages/spectrum/src/spectrum-control/InputDate.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { merge } from 'lodash';
2828
import { SpectrumInputProps } from './index';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { Flex } from '@adobe/react-spectrum';
31+
import { DatePicker, DatePickerLabel } from '../additional/DatePicker';
3132

3233
export class InputDate extends React.PureComponent<
3334
CellProps & SpectrumInputProps
@@ -53,15 +54,14 @@ export class InputDate extends React.PureComponent<
5354

5455
return (
5556
<Flex direction='column'>
56-
<label htmlFor={id + '-input'}>
57+
<DatePickerLabel htmlFor={id + '-input'}>
5758
{computeLabel(
5859
label,
5960
required,
6061
appliedUiSchemaOptions.hideRequiredAsterisk
6162
)}
62-
</label>
63-
<input
64-
style={{ marginTop: '3px', padding: '5px' }}
63+
</DatePickerLabel>
64+
<DatePicker
6565
width={width}
6666
type='date'
6767
value={data ?? ''}

packages/spectrum/src/spectrum-control/InputDateTime.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { CellProps, computeLabel } from '@jsonforms/core';
2828
import { merge } from 'lodash';
2929
import { SpectrumInputProps } from './index';
3030
import { Flex } from '@adobe/react-spectrum';
31+
import { DatePicker, DatePickerLabel } from '../additional/DatePicker';
3132

3233
export class InputDateTime extends React.PureComponent<
3334
CellProps & SpectrumInputProps
@@ -57,15 +58,14 @@ export class InputDateTime extends React.PureComponent<
5758

5859
return (
5960
<Flex direction='column'>
60-
<label htmlFor={id + '-input'}>
61+
<DatePickerLabel htmlFor={id + '-input'}>
6162
{computeLabel(
6263
label,
6364
required,
6465
appliedUiSchemaOptions.hideRequiredAsterisk
6566
)}
66-
</label>
67-
<input
68-
style={{ marginTop: '3px', padding: '5px' }}
67+
</DatePickerLabel>
68+
<DatePicker
6969
type='datetime-local'
7070
width={width}
7171
value={(data ?? '').substr(0, 16)}

packages/spectrum/src/spectrum-control/InputTime.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { merge } from 'lodash';
2828
import { SpectrumInputProps } from './index';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { Flex } from '@adobe/react-spectrum';
31+
import { DatePicker, DatePickerLabel } from '../additional/DatePicker';
3132

3233
export class InputTime extends React.PureComponent<
3334
CellProps & SpectrumInputProps
@@ -53,16 +54,15 @@ export class InputTime extends React.PureComponent<
5354

5455
return (
5556
<Flex direction='column'>
56-
<label htmlFor={id + '-input'}>
57+
<DatePickerLabel htmlFor={id + '-input'}>
5758
{computeLabel(
5859
label,
5960
required,
6061
appliedUiSchemaOptions.hideRequiredAsterisk
6162
)}
62-
</label>
63-
<input
63+
</DatePickerLabel>
64+
<DatePicker
6465
width={width}
65-
style={{ marginTop: '3px', padding: '5px' }}
6666
type='time'
6767
value={data ?? ''}
6868
onChange={(ev) => handleChange(path, ev.target.value)}

0 commit comments

Comments
 (0)