addons/components/DatetimePicker.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {ForwardedRef, ReactNode} from 'react';
b69ab319import type {ReactProps} from './utils';
b69ab3110
b69ab3111import * as stylex from '@stylexjs/stylex';
b69ab3112import {forwardRef, useId} from 'react';
b69ab3113import {Column} from './Flex';
b69ab3114
b69ab3115export const datetimePickerStyles = stylex.create({
b69ab3116 root: {
b69ab3117 gap: 0,
b69ab3118 },
b69ab3119 label: {
b69ab3120 marginBlock: '1px',
b69ab3121 },
b69ab3122 input: {
b69ab3123 boxSizing: 'border-box',
b69ab3124 height: '26px',
b69ab3125 padding: '0 9px',
b69ab3126 marginBlock: 0,
b69ab3127 minWidth: '100px',
b69ab3128 width: '100%',
b69ab3129 background: 'var(--input-background)',
b69ab3130 color: 'var(--input-foreground)',
b69ab3131 border: '1px solid var(--dropdown-border)',
b69ab3132 outline: {
b69ab3133 default: 'none',
b69ab3134 ':focus-visible': '1px solid var(--focus-border)',
b69ab3135 },
b69ab3136 outlineOffset: '-1px',
b69ab3137 },
b69ab3138});
b69ab3139
b69ab3140export const DatetimePicker = forwardRef(
b69ab3141 (
b69ab3142 {
b69ab3143 children,
b69ab3144 xstyle,
b69ab3145 containerXstyle,
b69ab3146 value,
b69ab3147 max,
b69ab3148 width,
b69ab3149 ...rest
b69ab3150 }: {
b69ab3151 children?: ReactNode;
b69ab3152 xstyle?: stylex.StyleXStyles;
b69ab3153 containerXstyle?: stylex.StyleXStyles;
b69ab3154 value?: string;
b69ab3155 max?: string;
b69ab3156 width?: string;
b69ab3157 placeholder?: string;
b69ab3158 readOnly?: boolean;
b69ab3159 } & ReactProps<HTMLInputElement>,
b69ab3160 ref: ForwardedRef<HTMLInputElement>,
b69ab3161 ) => {
b69ab3162 const id = useId();
b69ab3163 return (
b69ab3164 <Column
b69ab3165 xstyle={[datetimePickerStyles.root, containerXstyle ?? null]}
b69ab3166 style={{width}}
b69ab3167 alignStart>
b69ab3168 {children && (
b69ab3169 <label htmlFor={id} {...stylex.props(datetimePickerStyles.label)}>
b69ab3170 {children}
b69ab3171 </label>
b69ab3172 )}
b69ab3173 <input
b69ab3174 {...stylex.props(datetimePickerStyles.input, xstyle)}
b69ab3175 type="datetime-local"
b69ab3176 id={id}
b69ab3177 value={value}
b69ab3178 max={max}
b69ab3179 {...rest}
b69ab3180 ref={ref}
b69ab3181 />
b69ab3182 </Column>
b69ab3183 );
b69ab3184 },
b69ab3185);