diff --git a/src/components/input.tsx b/src/components/input.tsx index 32effd45..a680a0d1 100644 --- a/src/components/input.tsx +++ b/src/components/input.tsx @@ -1,5 +1,11 @@ import React from 'react'; -import { Form, Input, FormInputProps } from 'semantic-ui-react'; +import { + Form, + Input, + FormInputProps, + FormFieldProps, + Ref, +} from 'semantic-ui-react'; import { SemanticDatepickerProps } from '../types'; import CustomIcon from './icon'; @@ -7,12 +13,19 @@ type InputProps = FormInputProps & { clearIcon: SemanticDatepickerProps['clearIcon']; icon: SemanticDatepickerProps['icon']; isClearIconVisible: boolean; + fieldProps: FormFieldProps; + fieldRef: React.Ref; + children?: React.ReactNode; }; const inputData = { 'data-testid': 'datepicker-input', }; +const style: React.CSSProperties = { + position: 'relative', +}; + const CustomInput = React.forwardRef((props, ref) => { const { clearIcon, @@ -24,30 +37,38 @@ const CustomInput = React.forwardRef((props, ref) => { onFocus, required, value, + fieldProps, + fieldRef, + children, ...rest } = props; return ( - - {label && } - - } - input={inputData} - onFocus={onFocus} - value={value} - /> - + + + {label && ( + + )} + + } + input={inputData} + onFocus={onFocus} + value={value} + /> + {children} + + ); }); diff --git a/src/index.tsx b/src/index.tsx index a65dcc6e..98277b38 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,11 +18,6 @@ import { Locale, SemanticDatepickerProps } from './types'; import Calendar from './components/calendar'; import Input from './components/input'; -const style: React.CSSProperties = { - display: 'inline-block', - position: 'relative', -}; - const semanticInputProps = [ 'autoComplete', 'autoFocus', @@ -61,6 +56,14 @@ const semanticInputProps = [ 'readOnly', ]; +const semanticFormFieldProps = [ + 'disabled', + 'error', + 'inline', + 'required', + 'width', +]; + type SemanticDatepickerState = { isVisible: boolean; locale: Locale; @@ -153,6 +156,19 @@ class SemanticDatepicker extends React.Component< }; } + get fieldProps() { + const props = pick(semanticFormFieldProps, this.props); + const className = + this.props.fieldClassName !== undefined + ? this.props.fieldClassName + : null; + + return { + ...props, + className, + }; + } + get date(): Date | undefined { const { selectedDate } = this.state; const { date } = this.props; @@ -428,21 +444,22 @@ class SemanticDatepicker extends React.Component< return inline ? ( datepickerComponent ) : ( -
- + {isVisible && datepickerComponent} -
+ ); } } diff --git a/src/types/index.ts b/src/types/index.ts index 6f545cf2..89b6d2a5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,10 @@ import format from 'date-fns/format'; import { Props as DayzedProps, RenderProps } from 'dayzed'; -import { FormInputProps, SemanticICONS } from 'semantic-ui-react'; +import { + FormInputProps, + SemanticICONS, + SemanticWIDTHS, +} from 'semantic-ui-react'; export type Object = { [key: string]: any }; @@ -93,6 +97,8 @@ export type SemanticDatepickerProps = PickedDayzedProps & type: 'basic' | 'range'; datePickerOnly: boolean; value: DayzedProps['selected'] | null; + fieldClassName?: string; + width?: SemanticWIDTHS; }; export type BaseDatePickerProps = DayzedProps & {