|
| 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 | +}; |
0 commit comments