-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@mantine/core] Add InlineInput component to remove duplicated code f…
…rom Checkbox, Switch and Radio components
- Loading branch information
Showing
13 changed files
with
225 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createStyles, MantineSize } from '@mantine/styles'; | ||
|
||
const sizes = { | ||
xs: 16, | ||
sm: 20, | ||
md: 24, | ||
lg: 30, | ||
xl: 36, | ||
}; | ||
|
||
export interface InlineInputStylesParams { | ||
size: MantineSize; | ||
labelPosition: 'left' | 'right'; | ||
} | ||
|
||
export default createStyles((theme, { labelPosition, size }: InlineInputStylesParams) => ({ | ||
root: {}, | ||
|
||
body: { | ||
display: 'inline-flex', | ||
}, | ||
|
||
labelWrapper: { | ||
...theme.fn.fontStyles(), | ||
WebkitTapHighlightColor: 'transparent', | ||
fontSize: theme.fn.size({ size, sizes: theme.fontSizes }), | ||
lineHeight: `${theme.fn.size({ size, sizes })}px`, | ||
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black, | ||
cursor: theme.cursorType, | ||
order: labelPosition === 'left' ? 1 : 2, | ||
}, | ||
|
||
description: { | ||
marginTop: `calc(${theme.spacing.xs}px / 2)`, | ||
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm, | ||
}, | ||
|
||
error: { | ||
marginTop: `calc(${theme.spacing.xs}px / 2)`, | ||
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm, | ||
}, | ||
|
||
label: { | ||
cursor: theme.cursorType, | ||
[labelPosition === 'left' ? 'paddingRight' : 'paddingLeft']: theme.spacing.sm, | ||
|
||
'&[data-disabled]': { | ||
color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5], | ||
}, | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import { DefaultProps, MantineSize, Selectors } from '@mantine/styles'; | ||
import { Box } from '../Box'; | ||
import { Input } from '../Input'; | ||
import useStyles from './InlineInput.styles'; | ||
|
||
export type InlineInputStylesNames = Selectors<typeof useStyles>; | ||
|
||
export interface InlineInputProps | ||
extends DefaultProps<InlineInputStylesNames>, | ||
React.ComponentPropsWithoutRef<'div'> { | ||
__staticSelector: string; | ||
label: React.ReactNode; | ||
description: React.ReactNode; | ||
id: string; | ||
disabled: boolean; | ||
error: React.ReactNode; | ||
size: MantineSize; | ||
labelPosition: 'left' | 'right'; | ||
} | ||
|
||
export function InlineInput({ | ||
__staticSelector, | ||
className, | ||
classNames, | ||
styles, | ||
unstyled, | ||
children, | ||
label, | ||
description, | ||
id, | ||
disabled, | ||
error, | ||
size, | ||
labelPosition, | ||
...others | ||
}: InlineInputProps) { | ||
const { classes, cx } = useStyles( | ||
{ size, labelPosition }, | ||
{ name: __staticSelector, styles, classNames, unstyled } | ||
); | ||
|
||
return ( | ||
<Box className={cx(classes.root, className)} {...others}> | ||
<div className={cx(classes.body)}> | ||
{children} | ||
|
||
<div className={classes.labelWrapper}> | ||
{label && ( | ||
<label className={classes.label} data-disabled={disabled || undefined} htmlFor={id}> | ||
{label} | ||
</label> | ||
)} | ||
|
||
{description && ( | ||
<Input.Description className={classes.description}>{description}</Input.Description> | ||
)} | ||
|
||
{error && error !== 'boolean' && ( | ||
<Input.Error className={classes.error}>{error}</Input.Error> | ||
)} | ||
</div> | ||
</div> | ||
</Box> | ||
); | ||
} | ||
|
||
InlineInput.displayName = '@mantine/core/InlineInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { InlineInput } from './InlineInput'; | ||
export type { InlineInputProps, InlineInputStylesNames } from './InlineInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.