diff options
author | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2021-10-15 16:22:25 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 16:22:25 +0530 |
commit | ec15f83b947fb2daf4ca1a72e3af527dc89512a3 (patch) | |
tree | ea049cee5184a58b5bc09505e723cd19a736c4bd /src/components/ui/label | |
parent | chore: move 'packages/ui' into 'src' (no longer an injected package) (#2077) (diff) | |
download | ferdium-app-ec15f83b947fb2daf4ca1a72e3af527dc89512a3.tar.gz ferdium-app-ec15f83b947fb2daf4ca1a72e3af527dc89512a3.tar.zst ferdium-app-ec15f83b947fb2daf4ca1a72e3af527dc89512a3.zip |
chore: move 'packages/forms' into 'src' (no longer an injected package) (#2079)
Diffstat (limited to 'src/components/ui/label')
-rw-r--r-- | src/components/ui/label/index.tsx | 52 | ||||
-rw-r--r-- | src/components/ui/label/styles.ts | 12 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/components/ui/label/index.tsx b/src/components/ui/label/index.tsx new file mode 100644 index 000000000..4d86f23f7 --- /dev/null +++ b/src/components/ui/label/index.tsx | |||
@@ -0,0 +1,52 @@ | |||
1 | import classnames from 'classnames'; | ||
2 | import { Classes } from 'jss'; | ||
3 | import { Component, LabelHTMLAttributes } from 'react'; | ||
4 | import injectSheet from 'react-jss'; | ||
5 | |||
6 | import { IFormField } from '../typings/generic'; | ||
7 | |||
8 | import styles from './styles'; | ||
9 | |||
10 | interface ILabel extends IFormField, LabelHTMLAttributes<HTMLLabelElement> { | ||
11 | classes: Classes; | ||
12 | isRequired: boolean; | ||
13 | } | ||
14 | |||
15 | class LabelComponent extends Component<ILabel> { | ||
16 | static defaultProps = { | ||
17 | showLabel: true, | ||
18 | }; | ||
19 | |||
20 | render() { | ||
21 | const { | ||
22 | title, | ||
23 | showLabel, | ||
24 | classes, | ||
25 | className, | ||
26 | children, | ||
27 | htmlFor, | ||
28 | isRequired, | ||
29 | } = this.props; | ||
30 | |||
31 | if (!showLabel) return children; | ||
32 | |||
33 | return ( | ||
34 | <label | ||
35 | className={classnames({ | ||
36 | [`${className}`]: className, | ||
37 | })} | ||
38 | htmlFor={htmlFor} | ||
39 | > | ||
40 | {showLabel && ( | ||
41 | <span className={classes.label}> | ||
42 | {title} | ||
43 | {isRequired && ' *'} | ||
44 | </span> | ||
45 | )} | ||
46 | <div className={classes.content}>{children}</div> | ||
47 | </label> | ||
48 | ); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | export const Label = injectSheet(styles)(LabelComponent); | ||
diff --git a/src/components/ui/label/styles.ts b/src/components/ui/label/styles.ts new file mode 100644 index 000000000..0c9cef8bf --- /dev/null +++ b/src/components/ui/label/styles.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | |||
3 | export default (theme: Theme) => ({ | ||
4 | content: {}, | ||
5 | label: { | ||
6 | color: theme.labelColor, | ||
7 | fontSize: theme.uiFontSize, | ||
8 | }, | ||
9 | hasError: { | ||
10 | color: theme.brandDanger, | ||
11 | }, | ||
12 | }); | ||