Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix Input prefill style regression, add isPrefilled prop to Datepicker and Select #754

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions react/src/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ FixedHeightCalendarPopover.args = {
isCalendarFixedHeight: true,
}

export const Prefilled = Template.bind({})
Prefilled.args = {
isPrefilled: true,
}

export const SizeSmall = Template.bind({})
SizeSmall.args = {
size: 'sm',
Expand Down
2 changes: 2 additions & 0 deletions react/src/DatePicker/DatePickerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const useProvideDatePicker = ({
isReadOnly: isReadOnlyProp,
isRequired: isRequiredProp,
isInvalid: isInvalidProp,
isPrefilled,
locale,
allowManualInput = true,
allowInvalidDates = true,
Expand Down Expand Up @@ -260,6 +261,7 @@ const useProvideDatePicker = ({
const styles = useMultiStyleConfig('DatePicker', {
size,
colorScheme,
isPrefilled,
})

const placeholder = useMemo(
Expand Down
3 changes: 3 additions & 0 deletions react/src/DatePicker/components/DatePickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const DatePickerInput = forwardRef<{}, 'input'>((_props, ref) => {
size,
inputPattern,
innerRef,
styles,
} = useDatePicker()

const mergedInputRef = useMergeRefs(inputRef, innerRef, ref)
Expand Down Expand Up @@ -71,13 +72,15 @@ export const DatePickerInput = forwardRef<{}, 'input'>((_props, ref) => {
onBlur={handleInputBlur}
onClick={handleInputClick}
isReadOnly={fcProps.isReadOnly || !allowManualInput}
sx={styles.field}
/>
) : (
<Input
size={size}
inputMode="numeric"
placeholder={placeholder}
pattern={inputPattern}
sx={styles.field}
/>
)}
<InputRightAddon p={0} border="none">
Expand Down
4 changes: 4 additions & 0 deletions react/src/DatePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface DatePickerBaseProps
* @defaultValue `true`
*/
allowInvalidDates?: boolean
/**
* Whether the input is in a prefilled state.
*/
isPrefilled?: boolean
/**
* Whether the calendar will close once a date is selected.
* @defaultValue `true`
Expand Down
6 changes: 6 additions & 0 deletions react/src/DateRangePicker/DateRangePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ DatePickerDisabled.args = {
defaultValue: [new Date('2001-01-01'), new Date('2002-01-03')],
}

export const Prefilled = Template.bind({})
Prefilled.args = {
isPrefilled: true,
defaultValue: [new Date('2001-01-01'), new Date('2002-01-03')],
}

export const Mobile = Template.bind({})
Mobile.parameters = getMobileViewParameters()

Expand Down
2 changes: 2 additions & 0 deletions react/src/DateRangePicker/DateRangePickerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const useProvideDateRangePicker = ({
isReadOnly: isReadOnlyProp,
isRequired: isRequiredProp,
isInvalid: isInvalidProp,
isPrefilled,
locale,
allowManualInput = true,
allowInvalidDates = true,
Expand Down Expand Up @@ -333,6 +334,7 @@ const useProvideDateRangePicker = ({
const styles = useMultiStyleConfig('DateRangePicker', {
size,
colorScheme,
isPrefilled,
})

const placeholder = useMemo(
Expand Down
8 changes: 7 additions & 1 deletion react/src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export const Input = forwardRef<InputProps, 'input'>((props, ref) => {

// Return normal input component if not success state.
if (!props.isSuccess) {
return <ChakraInput ref={ref} __css={inputStyles.field} {...inputProps} />
return (
<ChakraInput
ref={ref}
sx={merge({}, inputStyles.field, props.sx)}
{...inputProps}
/>
)
}

return (
Expand Down
6 changes: 6 additions & 0 deletions react/src/MultiSelect/MultiSelect.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ DisabledWithSelection.args = {
values: ['What happens when the label is fairly long', 'Bat'],
}

export const Prefilled = Template.bind({})
Prefilled.args = {
isPrefilled: true,
values: ['What happens when the label is fairly long', 'Bat'],
}

export const WithFixedItemHeight = Template.bind({})
WithFixedItemHeight.args = {
size: 'md',
Expand Down
6 changes: 6 additions & 0 deletions react/src/MultiSelect/MultiSelectProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export interface MultiSelectProviderProps<
* If `true`, the selected items will take up the full width of the input container. Defaults to `false`.
*/
isStretchLayout?: boolean
/**
* Whether the input is in a prefilled state.
*/
isPrefilled?: boolean
}
export const MultiSelectProvider = ({
items: rawItems,
Expand All @@ -81,6 +85,7 @@ export const MultiSelectProvider = ({
placeholder: placeholderProp,
clearButtonLabel = 'Clear selection',
isSearchable = true,
isPrefilled = false,
defaultIsOpen,
isInvalid: isInvalidProp,
isReadOnly: isReadOnlyProp,
Expand Down Expand Up @@ -297,6 +302,7 @@ export const MultiSelectProvider = ({
size,
isFocused: isFocused || isOpen,
isEmpty: selectedItems.length === 0,
isPrefilled,
})

const virtualListHeight = useMemo(() => {
Expand Down
6 changes: 6 additions & 0 deletions react/src/SingleSelect/SingleSelect.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ Disabled.args = {
isDisabled: true,
}

export const Prefilled = Template.bind({})
Prefilled.args = {
isPrefilled: true,
value: itemToValue(INITIAL_COMBOBOX_ITEMS[2]),
}

export const FormInput: StoryFn<SingleSelectProps> = (args) => {
const [value, setValue] = useState<string>(args.value)

Expand Down
6 changes: 6 additions & 0 deletions react/src/SingleSelect/SingleSelectProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export interface SingleSelectProviderProps<
/** Color scheme of component */
colorScheme?: ThemingProps<'SingleSelect'>['colorScheme']
fixedItemHeight?: number
/**
* Whether the input is in a prefilled state.
*/
isPrefilled?: boolean
}
export const SingleSelectProvider = ({
items: rawItems,
Expand All @@ -51,6 +55,7 @@ export const SingleSelectProvider = ({
clearButtonLabel = 'Clear selection',
isClearable = true,
isSearchable = true,
isPrefilled = false,
initialIsOpen,
isInvalid: isInvalidProp,
isReadOnly: isReadOnlyProp,
Expand Down Expand Up @@ -234,6 +239,7 @@ export const SingleSelectProvider = ({
const styles = useMultiStyleConfig('SingleSelect', {
size,
isClearable,
isPrefilled,
colorScheme,
})

Expand Down
28 changes: 20 additions & 8 deletions react/src/theme/components/DatePicker.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
import { anatomy } from '@chakra-ui/theme-tools'
import { memoizedGet as get } from '@chakra-ui/utils'
import omit from 'lodash/omit'

import { Input } from './Input'

export const datepickerAnatomy = anatomy('datepicker').parts(
'header',
'inputButton',
'container',
'calendarButton',
'field',
)
const { defineMultiStyleConfig, definePartsStyle } =
createMultiStyleConfigHelpers(datepickerAnatomy.keys)

const sizes = {
xs: definePartsStyle({
xs: definePartsStyle((props) => ({
field: Input.sizes?.xs(props).field,
inputButton: {
fontSize: '1rem',
},
}),
sm: definePartsStyle({
})),
sm: definePartsStyle((props) => ({
field: Input.sizes?.sm(props).field,
inputButton: {
fontSize: '1.25rem',
},
}),
md: definePartsStyle({
})),
md: definePartsStyle((props) => ({
field: Input.sizes?.md(props).field,
inputButton: {
fontSize: '1.25rem',
},
}),
})),
}

const baseStyle = definePartsStyle(({ theme }) => {
const themeTextStyles = get(theme, 'textStyles')
const baseStyle = definePartsStyle((props) => {
const themeTextStyles = get(props.theme, 'textStyles')
const inputFieldStyle = omit(
Input.variants?.outline(props).field,
'borderRadius',
)
return {
container: {
bg: 'utility.ui',
},
field: inputFieldStyle,
calendarButton: {
_active: {
zIndex: '1',
Expand Down
9 changes: 5 additions & 4 deletions react/src/theme/components/DateRangePicker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
import omit from 'lodash/omit'

import { DatePicker, datepickerAnatomy } from './DatePicker'
import { Input } from './Input'
Expand Down Expand Up @@ -40,19 +41,19 @@ const sizes = {
xs: definePartsStyle((props) => {
return {
fieldwrapper: Input.sizes?.xs(props).field,
inputButton: DatePicker.sizes?.xs.inputButton,
inputButton: DatePicker.sizes?.xs(props).inputButton,
}
}),
sm: definePartsStyle((props) => {
return {
fieldwrapper: Input.sizes?.sm(props).field,
inputButton: DatePicker.sizes?.sm.inputButton,
inputButton: DatePicker.sizes?.sm(props).inputButton,
}
}),
md: definePartsStyle((props) => {
return {
fieldwrapper: Input.sizes?.md(props).field,
inputButton: DatePicker.sizes?.md.inputButton,
inputButton: DatePicker.sizes?.md(props).inputButton,
}
}),
}
Expand All @@ -64,7 +65,7 @@ const variants = {
export const DateRangePicker = defineMultiStyleConfig({
variants,
sizes,
baseStyle: DatePicker.baseStyle,
baseStyle: (props) => omit(DatePicker.baseStyle?.(props), 'field'),
defaultProps: {
variant: 'outline',
size: 'md',
Expand Down
Loading