| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type {ForwardedRef, ReactNode} from 'react'; |
| 9 | import type {ReactProps} from './utils'; |
| 10 | |
| 11 | import * as stylex from '@stylexjs/stylex'; |
| 12 | import {forwardRef, useId} from 'react'; |
| 13 | import {Column} from './Flex'; |
| 14 | |
| 15 | export const datetimePickerStyles = stylex.create({ |
| 16 | root: { |
| 17 | gap: 0, |
| 18 | }, |
| 19 | label: { |
| 20 | marginBlock: '1px', |
| 21 | }, |
| 22 | input: { |
| 23 | boxSizing: 'border-box', |
| 24 | height: '26px', |
| 25 | padding: '0 9px', |
| 26 | marginBlock: 0, |
| 27 | minWidth: '100px', |
| 28 | width: '100%', |
| 29 | background: 'var(--input-background)', |
| 30 | color: 'var(--input-foreground)', |
| 31 | border: '1px solid var(--dropdown-border)', |
| 32 | outline: { |
| 33 | default: 'none', |
| 34 | ':focus-visible': '1px solid var(--focus-border)', |
| 35 | }, |
| 36 | outlineOffset: '-1px', |
| 37 | }, |
| 38 | }); |
| 39 | |
| 40 | export const DatetimePicker = forwardRef( |
| 41 | ( |
| 42 | { |
| 43 | children, |
| 44 | xstyle, |
| 45 | containerXstyle, |
| 46 | value, |
| 47 | max, |
| 48 | width, |
| 49 | ...rest |
| 50 | }: { |
| 51 | children?: ReactNode; |
| 52 | xstyle?: stylex.StyleXStyles; |
| 53 | containerXstyle?: stylex.StyleXStyles; |
| 54 | value?: string; |
| 55 | max?: string; |
| 56 | width?: string; |
| 57 | placeholder?: string; |
| 58 | readOnly?: boolean; |
| 59 | } & ReactProps<HTMLInputElement>, |
| 60 | ref: ForwardedRef<HTMLInputElement>, |
| 61 | ) => { |
| 62 | const id = useId(); |
| 63 | return ( |
| 64 | <Column |
| 65 | xstyle={[datetimePickerStyles.root, containerXstyle ?? null]} |
| 66 | style={{width}} |
| 67 | alignStart> |
| 68 | {children && ( |
| 69 | <label htmlFor={id} {...stylex.props(datetimePickerStyles.label)}> |
| 70 | {children} |
| 71 | </label> |
| 72 | )} |
| 73 | <input |
| 74 | {...stylex.props(datetimePickerStyles.input, xstyle)} |
| 75 | type="datetime-local" |
| 76 | id={id} |
| 77 | value={value} |
| 78 | max={max} |
| 79 | {...rest} |
| 80 | ref={ref} |
| 81 | /> |
| 82 | </Column> |
| 83 | ); |
| 84 | }, |
| 85 | ); |
| 86 | |