@toptal/picasso-form 6.1.9-alpha-ff-x-replace-overflow-hidden-by-clip-popper-4c9b94a3e.1 → 6.2.1-alpha-ff-x-replace-overflow-hidden-by-clip-popper-9796ca8c3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist-package/src/Form/Form.d.ts +1 -1
  2. package/dist-package/src/Form/Form.d.ts.map +1 -1
  3. package/dist-package/src/Form/Form.js +1 -1
  4. package/dist-package/src/Form/Form.js.map +1 -1
  5. package/dist-package/src/FormActionsContainer/FormActionsContainer.js +1 -1
  6. package/dist-package/src/FormActionsContainer/FormActionsContainer.js.map +1 -1
  7. package/dist-package/src/FormCompound/index.d.ts +1 -1
  8. package/dist-package/src/FormCompound/index.d.ts.map +1 -1
  9. package/dist-package/src/FormCompound/index.js +1 -1
  10. package/dist-package/src/FormCompound/index.js.map +1 -1
  11. package/dist-package/src/FormField/FormField.js +1 -1
  12. package/dist-package/src/FormField/FormField.js.map +1 -1
  13. package/dist-package/src/FormField/styles.d.ts +1 -1
  14. package/dist-package/src/FormField/styles.d.ts.map +1 -1
  15. package/dist-package/src/FormField/styles.js +1 -1
  16. package/dist-package/src/FormField/styles.js.map +1 -1
  17. package/dist-package/src/FormLevelError/FormLevelError.d.ts +9 -0
  18. package/dist-package/src/FormLevelError/FormLevelError.d.ts.map +1 -0
  19. package/dist-package/src/FormLevelError/FormLevelError.js +23 -0
  20. package/dist-package/src/FormLevelError/FormLevelError.js.map +1 -0
  21. package/dist-package/src/FormLevelError/index.d.ts +2 -0
  22. package/dist-package/src/FormLevelError/index.d.ts.map +1 -0
  23. package/dist-package/src/FormLevelError/index.js +2 -0
  24. package/dist-package/src/FormLevelError/index.js.map +1 -0
  25. package/dist-package/src/FormLevelWarning/FormLevelWarning.d.ts +9 -0
  26. package/dist-package/src/FormLevelWarning/FormLevelWarning.d.ts.map +1 -0
  27. package/dist-package/src/FormLevelWarning/FormLevelWarning.js +23 -0
  28. package/dist-package/src/FormLevelWarning/FormLevelWarning.js.map +1 -0
  29. package/dist-package/src/FormLevelWarning/index.d.ts +2 -0
  30. package/dist-package/src/FormLevelWarning/index.d.ts.map +1 -0
  31. package/dist-package/src/FormLevelWarning/index.js +2 -0
  32. package/dist-package/src/FormLevelWarning/index.js.map +1 -0
  33. package/dist-package/src/index.d.ts +4 -3
  34. package/dist-package/src/index.d.ts.map +1 -1
  35. package/dist-package/src/index.js +3 -3
  36. package/dist-package/src/index.js.map +1 -1
  37. package/package.json +15 -12
  38. package/src/Form/Form.tsx +2 -3
  39. package/src/Form/story/Error.example.tsx +50 -0
  40. package/src/Form/story/Warning.example.tsx +50 -0
  41. package/src/Form/story/index.jsx +18 -1
  42. package/src/FormActionsContainer/FormActionsContainer.tsx +1 -1
  43. package/src/FormCompound/index.ts +2 -1
  44. package/src/FormField/FormField.tsx +1 -1
  45. package/src/FormField/styles.ts +2 -3
  46. package/src/FormField/test.tsx +4 -4
  47. package/src/FormLevelError/FormLevelError.tsx +31 -0
  48. package/src/FormLevelError/index.ts +1 -0
  49. package/src/FormLevelWarning/FormLevelWarning.tsx +31 -0
  50. package/src/FormLevelWarning/index.ts +1 -0
  51. package/src/index.ts +14 -3
  52. package/dist-package/src/FieldsLayout/FieldsLayoutContext.d.ts +0 -20
  53. package/dist-package/src/FieldsLayout/FieldsLayoutContext.d.ts.map +0 -1
  54. package/dist-package/src/FieldsLayout/FieldsLayoutContext.js +0 -17
  55. package/dist-package/src/FieldsLayout/FieldsLayoutContext.js.map +0 -1
  56. package/dist-package/src/FieldsLayout/index.d.ts +0 -2
  57. package/dist-package/src/FieldsLayout/index.d.ts.map +0 -1
  58. package/dist-package/src/FieldsLayout/index.js +0 -2
  59. package/dist-package/src/FieldsLayout/index.js.map +0 -1
  60. package/dist-package/src/FormControlLabel/FormControlLabel.d.ts +0 -23
  61. package/dist-package/src/FormControlLabel/FormControlLabel.d.ts.map +0 -1
  62. package/dist-package/src/FormControlLabel/FormControlLabel.js +0 -26
  63. package/dist-package/src/FormControlLabel/FormControlLabel.js.map +0 -1
  64. package/dist-package/src/FormControlLabel/index.d.ts +0 -5
  65. package/dist-package/src/FormControlLabel/index.d.ts.map +0 -1
  66. package/dist-package/src/FormControlLabel/index.js +0 -2
  67. package/dist-package/src/FormControlLabel/index.js.map +0 -1
  68. package/dist-package/src/FormLabel/FormLabel.d.ts +0 -30
  69. package/dist-package/src/FormLabel/FormLabel.d.ts.map +0 -1
  70. package/dist-package/src/FormLabel/FormLabel.js +0 -37
  71. package/dist-package/src/FormLabel/FormLabel.js.map +0 -1
  72. package/dist-package/src/FormLabel/index.d.ts +0 -6
  73. package/dist-package/src/FormLabel/index.d.ts.map +0 -1
  74. package/dist-package/src/FormLabel/index.js +0 -2
  75. package/dist-package/src/FormLabel/index.js.map +0 -1
  76. package/dist-package/src/FormLabel/styles.d.ts +0 -12
  77. package/dist-package/src/FormLabel/styles.d.ts.map +0 -1
  78. package/dist-package/src/FormLabel/styles.js +0 -24
  79. package/dist-package/src/FormLabel/styles.js.map +0 -1
  80. package/src/FieldsLayout/FieldsLayoutContext.tsx +0 -53
  81. package/src/FieldsLayout/index.ts +0 -1
  82. package/src/FormControlLabel/FormControlLabel.tsx +0 -84
  83. package/src/FormControlLabel/index.ts +0 -6
  84. package/src/FormLabel/FormLabel.tsx +0 -106
  85. package/src/FormLabel/__snapshots__/test.tsx.snap +0 -146
  86. package/src/FormLabel/index.ts +0 -7
  87. package/src/FormLabel/story/index.jsx +0 -6
  88. package/src/FormLabel/styles.ts +0 -66
  89. package/src/FormLabel/test.tsx +0 -111
@@ -0,0 +1,31 @@
1
+ import React, { forwardRef } from 'react'
2
+ import type { ReactNode, HTMLAttributes } from 'react'
3
+ import type { BaseProps } from '@toptal/picasso-shared'
4
+ import { Alert } from '@toptal/picasso-alert'
5
+ import { Container } from '@toptal/picasso-container'
6
+ import { twMerge } from '@toptal/picasso-tailwind-merge'
7
+
8
+ export interface Props extends BaseProps, HTMLAttributes<HTMLDivElement> {
9
+ children: ReactNode
10
+ }
11
+
12
+ export const FormLevelWarning = forwardRef<HTMLDivElement, Props>(
13
+ function FormLevelWarning(props, ref) {
14
+ const { children, className, style, ...rest } = props
15
+
16
+ return (
17
+ <Container
18
+ {...rest}
19
+ ref={ref}
20
+ className={twMerge('mt-4', className)}
21
+ style={style}
22
+ >
23
+ <Alert variant='yellow'>{children}</Alert>
24
+ </Container>
25
+ )
26
+ }
27
+ )
28
+
29
+ FormLevelWarning.displayName = 'FormLevelWarning'
30
+
31
+ export default FormLevelWarning
@@ -0,0 +1 @@
1
+ export { default } from './FormLevelWarning'
package/src/index.ts CHANGED
@@ -3,9 +3,20 @@ export * from './Form'
3
3
  export * from './FormError'
4
4
  export * from './FormHint'
5
5
  export * from './FormField'
6
- export * from './FormControlLabel'
7
- export * from './FormLabel'
8
- export * from './FieldsLayout'
6
+ export type {
7
+ FieldsLayoutContextProviderProps,
8
+ FieldsLayoutContextValue,
9
+ FieldLayout,
10
+ LabelColumnSize,
11
+ ResponsiveLabelColumnSize,
12
+ } from '@toptal/picasso-form-layout'
13
+ export {
14
+ useFieldsLayoutContext,
15
+ FieldsLayoutContextProvider,
16
+ } from '@toptal/picasso-form-layout'
17
+
9
18
  export * from './FormAutoSaveIndicator'
10
19
  export * from './FieldRequirements'
11
20
  export * from './FormActionsContainer'
21
+ export { default as FormLevelError } from './FormLevelError'
22
+ export { default as FormLevelWarning } from './FormLevelWarning'
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import type { BreakpointKeys } from '@toptal/picasso-utils';
3
- export declare type LabelColumnSize = 2 | 3 | 4;
4
- export declare type ResponsiveLabelColumnSize = {
5
- [k in BreakpointKeys]?: LabelColumnSize;
6
- };
7
- export declare type FieldLayout = 'horizontal' | 'vertical';
8
- export declare type FieldsLayoutContextValue = {
9
- layout: FieldLayout;
10
- labelWidth: LabelColumnSize | ResponsiveLabelColumnSize;
11
- };
12
- export declare const DEFAULT_LABEL_WIDTH_SIZE: LabelColumnSize;
13
- export declare type FieldsLayoutContextProviderProps = {
14
- layout?: FieldLayout;
15
- labelWidth?: LabelColumnSize | ResponsiveLabelColumnSize;
16
- children: React.ReactNode;
17
- };
18
- export declare const FieldsLayoutContextProvider: ({ layout, labelWidth, children, }: FieldsLayoutContextProviderProps) => JSX.Element;
19
- export declare const useFieldsLayoutContext: () => FieldsLayoutContextValue;
20
- //# sourceMappingURL=FieldsLayoutContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldsLayoutContext.d.ts","sourceRoot":"","sources":["../../../src/FieldsLayout/FieldsLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAA;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE3D,oBAAY,eAAe,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEvC,oBAAY,yBAAyB,GAAG;KACrC,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,eAAe;CACxC,CAAA;AAED,oBAAY,WAAW,GAAG,YAAY,GAAG,UAAU,CAAA;AAEnD,oBAAY,wBAAwB,GAAG;IACrC,MAAM,EAAE,WAAW,CAAA;IACnB,UAAU,EAAE,eAAe,GAAG,yBAAyB,CAAA;CACxD,CAAA;AAED,eAAO,MAAM,wBAAwB,EAAE,eAAmB,CAAA;AAO1D,oBAAY,gCAAgC,GAAG;IAC7C,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,UAAU,CAAC,EAAE,eAAe,GAAG,yBAAyB,CAAA;IACxD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,2BAA2B,sCAIrC,gCAAgC,gBAgBlC,CAAA;AAED,eAAO,MAAM,sBAAsB,gCAAwC,CAAA"}
@@ -1,17 +0,0 @@
1
- import React, { createContext, useContext, useMemo } from 'react';
2
- import { useBreakpoint } from '@toptal/picasso-utils';
3
- export const DEFAULT_LABEL_WIDTH_SIZE = 3;
4
- const FieldsLayoutContext = createContext({
5
- layout: 'vertical',
6
- labelWidth: DEFAULT_LABEL_WIDTH_SIZE,
7
- });
8
- export const FieldsLayoutContextProvider = ({ layout = 'vertical', labelWidth = DEFAULT_LABEL_WIDTH_SIZE, children, }) => {
9
- const isSmallScreen = useBreakpoint(['sm', 'xs']);
10
- const value = useMemo(() => ({
11
- layout: isSmallScreen ? 'vertical' : layout,
12
- labelWidth,
13
- }), [layout, isSmallScreen, labelWidth]);
14
- return (React.createElement(FieldsLayoutContext.Provider, { value: value }, children));
15
- };
16
- export const useFieldsLayoutContext = () => useContext(FieldsLayoutContext);
17
- //# sourceMappingURL=FieldsLayoutContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FieldsLayoutContext.js","sourceRoot":"","sources":["../../../src/FieldsLayout/FieldsLayoutContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAgBrD,MAAM,CAAC,MAAM,wBAAwB,GAAoB,CAAC,CAAA;AAE1D,MAAM,mBAAmB,GAAG,aAAa,CAA2B;IAClE,MAAM,EAAE,UAAU;IAClB,UAAU,EAAE,wBAAwB;CACrC,CAAC,CAAA;AAQF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,EAC1C,MAAM,GAAG,UAAU,EACnB,UAAU,GAAG,wBAAwB,EACrC,QAAQ,GACyB,EAAE,EAAE;IACrC,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IAEjD,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM;QAC3C,UAAU;KACX,CAAC,EACF,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CACpC,CAAA;IAED,OAAO,CACL,oBAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACvC,QAAQ,CACoB,CAChC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './FieldsLayoutContext';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/FieldsLayout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './FieldsLayoutContext';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/FieldsLayout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -1,23 +0,0 @@
1
- import type { ReactElement, ReactNode, LabelHTMLAttributes } from 'react';
2
- import React from 'react';
3
- import type { FormControlLabelProps } from '@material-ui/core/FormControlLabel';
4
- import type { StandardProps, TextLabelProps } from '@toptal/picasso-shared';
5
- import type { RequiredDecoration } from '../FormLabel';
6
- export declare type FormControlLabelAttributesType = LabelHTMLAttributes<HTMLLabelElement> & Pick<FormControlLabelProps, 'onChange'>;
7
- export interface Props extends StandardProps, TextLabelProps, FormControlLabelAttributesType {
8
- /** A control element. For instance, it can be be a Radio or a Checkbox */
9
- control: ReactElement;
10
- /** The text to be used in an enclosing label element */
11
- label?: ReactNode;
12
- /** Shows whether label is disabled or not */
13
- disabled?: boolean;
14
- /** Whether to show asterisk or (optional) postfix as a 'required' decoration */
15
- requiredDecoration?: RequiredDecoration;
16
- classes?: {
17
- root?: string;
18
- label?: string;
19
- };
20
- }
21
- declare const FormControlLabel: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLLabelElement>>;
22
- export default FormControlLabel;
23
- //# sourceMappingURL=FormControlLabel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormControlLabel.d.ts","sourceRoot":"","sources":["../../../src/FormControlLabel/FormControlLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,KAAqB,MAAM,OAAO,CAAA;AACzC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAG3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAItD,oBAAY,8BAA8B,GACxC,mBAAmB,CAAC,gBAAgB,CAAC,GACnC,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAA;AAE3C,MAAM,WAAW,KACf,SAAQ,aAAa,EACnB,cAAc,EACd,8BAA8B;IAChC,0EAA0E;IAC1E,OAAO,EAAE,YAAY,CAAA;IACrB,wDAAwD;IACxD,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,QAAA,MAAM,gBAAgB,gFA+CrB,CAAA;AAID,eAAe,gBAAgB,CAAA"}
@@ -1,26 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React, { forwardRef } from 'react';
13
- import { twMerge } from '@toptal/picasso-tailwind-merge';
14
- import { FormCompound as Form } from '../FormCompound';
15
- import { useFieldsLayoutContext } from '../FieldsLayout';
16
- const FormControlLabel = forwardRef(function FormControlLabel(props, ref) {
17
- const { control, label, className, style, disabled, requiredDecoration, titleCase, classes } = props, rest = __rest(props, ["control", "label", "className", "style", "disabled", "requiredDecoration", "titleCase", "classes"]);
18
- const { layout } = useFieldsLayoutContext();
19
- const isHorizontalLayout = layout === 'horizontal';
20
- return (React.createElement("label", Object.assign({}, rest, { ref: ref, className: twMerge('inline-flex items-center', 'max-w-full', 'align-middle', '-webkit-tap-highlight-color-transparent', 'mx-0', disabled ? 'cursor-default' : 'cursor-pointer', isHorizontalLayout && 'col-start-1 col-span-2', classes === null || classes === void 0 ? void 0 : classes.root, className), style: style }),
21
- React.cloneElement(control, { disabled }),
22
- React.createElement(Form.Label, { className: twMerge(disabled && 'pointer-events-auto', classes === null || classes === void 0 ? void 0 : classes.label), as: 'span', requiredDecoration: requiredDecoration, disabled: disabled, titleCase: titleCase }, label)));
23
- });
24
- FormControlLabel.displayName = 'FormControlLabel';
25
- export default FormControlLabel;
26
- //# sourceMappingURL=FormControlLabel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormControlLabel.js","sourceRoot":"","sources":["../../../src/FormControlLabel/FormControlLabel.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAGxD,OAAO,EAAE,YAAY,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAwBxD,MAAM,gBAAgB,GAAG,UAAU,CACjC,SAAS,gBAAgB,CAAC,KAAK,EAAE,GAAG;IAClC,MAAM,EACJ,OAAO,EACP,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,OAAO,KAEL,KAAK,EADJ,IAAI,UACL,KAAK,EAVH,oGAUL,CAAQ,CAAA;IAET,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAC3C,MAAM,kBAAkB,GAAG,MAAM,KAAK,YAAY,CAAA;IAElD,OAAO,CACL,+CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,OAAO,CAChB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,yCAAyC,EACzC,MAAM,EACN,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,EAC9C,kBAAkB,IAAI,wBAAwB,EAC9C,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EACb,SAAS,CACV,EACD,KAAK,EAAE,KAAK;QAEX,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC;QAC1C,oBAAC,IAAI,CAAC,KAAK,IACT,SAAS,EAAE,OAAO,CAAC,QAAQ,IAAI,qBAAqB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,EACrE,EAAE,EAAC,MAAM,EACT,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,IAEnB,KAAK,CACK,CACP,CACT,CAAA;AACH,CAAC,CACF,CAAA;AAED,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAA;AAEjD,eAAe,gBAAgB,CAAA"}
@@ -1,5 +0,0 @@
1
- import type { OmitInternalProps } from '@toptal/picasso-shared';
2
- import type { Props } from './FormControlLabel';
3
- export { default as FormControlLabel } from './FormControlLabel';
4
- export declare type FormControlLabelProps = OmitInternalProps<Props>;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/FormControlLabel/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAChE,oBAAY,qBAAqB,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export { default as FormControlLabel } from './FormControlLabel';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/FormControlLabel/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -1,30 +0,0 @@
1
- import type { HTMLAttributes, ReactNode } from 'react';
2
- import React from 'react';
3
- import type { BaseProps, TextLabelProps, SizeType } from '@toptal/picasso-shared';
4
- declare type ComponentType = 'label' | 'span';
5
- export declare type RequiredDecoration = 'asterisk' | 'optional';
6
- export declare type Size = SizeType<'medium' | 'large'>;
7
- export declare type Alignment = 'top' | 'middle';
8
- export interface Props extends BaseProps, TextLabelProps, HTMLAttributes<HTMLLabelElement | HTMLSpanElement> {
9
- /** Content of the label */
10
- children: ReactNode;
11
- /** Whether to show asterisk or (optional) postfix as a 'required' decoration */
12
- requiredDecoration?: RequiredDecoration;
13
- /** Is this label for disabled input or not */
14
- disabled?: boolean;
15
- /** Specifies an id of the input */
16
- htmlFor?: string;
17
- /** Whether label should act as inline element `display: inline-block` */
18
- inline?: boolean;
19
- /** Component used for the root node */
20
- as?: ComponentType;
21
- /** Component size */
22
- size?: Size;
23
- /** Whether label should be aligned to top of the container or not */
24
- alignment?: Alignment;
25
- /** Label's end adornment */
26
- labelEndAdornment?: ReactNode;
27
- }
28
- export declare const FormLabel: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLLabelElement>>;
29
- export default FormLabel;
30
- //# sourceMappingURL=FormLabel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormLabel.d.ts","sourceRoot":"","sources":["../../../src/FormLabel/FormLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,KAAqB,MAAM,OAAO,CAAA;AACzC,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACT,MAAM,wBAAwB,CAAA;AAQ/B,aAAK,aAAa,GAAG,OAAO,GAAG,MAAM,CAAA;AACrC,oBAAY,kBAAkB,GAAG,UAAU,GAAG,UAAU,CAAA;AAExD,oBAAY,IAAI,GAAG,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAA;AAC/C,oBAAY,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAA;AAExC,MAAM,WAAW,KACf,SAAQ,SAAS,EACf,cAAc,EACd,cAAc,CAAC,gBAAgB,GAAG,eAAe,CAAC;IACpD,2BAA2B;IAC3B,QAAQ,EAAE,SAAS,CAAA;IACnB,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,uCAAuC;IACvC,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,qBAAqB;IACrB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,qEAAqE;IACrE,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,4BAA4B;IAC5B,iBAAiB,CAAC,EAAE,SAAS,CAAA;CAC9B;AAED,eAAO,MAAM,SAAS,gFAmDpB,CAAA;AAUF,eAAe,SAAS,CAAA"}
@@ -1,37 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React, { forwardRef } from 'react';
13
- import { useTitleCase } from '@toptal/picasso-shared';
14
- import { toTitleCase } from '@toptal/picasso-utils';
15
- import { twMerge } from '@toptal/picasso-tailwind-merge';
16
- import { classesBySize, getRootClasses } from './styles';
17
- import { useFieldsLayoutContext } from '../FieldsLayout';
18
- export const FormLabel = forwardRef(function FormLabel(props, ref) {
19
- const { children, disabled, htmlFor, className, style, inline, as: Component = 'label', titleCase: propsTitleCase, requiredDecoration, size = 'medium', alignment = 'middle', labelEndAdornment } = props, rest = __rest(props, ["children", "disabled", "htmlFor", "className", "style", "inline", "as", "titleCase", "requiredDecoration", "size", "alignment", "labelEndAdornment"]);
20
- const isInline = inline || Component === 'span';
21
- const titleCase = useTitleCase(propsTitleCase);
22
- const { layout } = useFieldsLayoutContext();
23
- return (React.createElement(Component, Object.assign({}, rest, { ref: ref, htmlFor: htmlFor, className: twMerge(getRootClasses({ disabled, isInline, layout, alignment }), className), style: style }),
24
- React.createElement("span", { className: isInline ? 'align-top text-[0.8125rem]' : classesBySize[size] },
25
- requiredDecoration === 'asterisk' && (React.createElement("span", { className: 'align-top text-red-500 mr-[0.3125em]' }, "*")),
26
- titleCase ? toTitleCase(children) : children,
27
- requiredDecoration === 'optional' && ' (optional)',
28
- labelEndAdornment)));
29
- });
30
- FormLabel.defaultProps = {
31
- as: 'label',
32
- inline: false,
33
- size: 'medium',
34
- };
35
- FormLabel.displayName = 'FormLabel';
36
- export default FormLabel;
37
- //# sourceMappingURL=FormLabel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormLabel.js","sourceRoot":"","sources":["../../../src/FormLabel/FormLabel.tsx"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAMzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAgCxD,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAA0B,SAAS,SAAS,CAC7E,KAAK,EACL,GAAG;IAEH,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EACL,MAAM,EACN,EAAE,EAAE,SAAS,GAAG,OAAO,EACvB,SAAS,EAAE,cAAc,EACzB,kBAAkB,EAClB,IAAI,GAAG,QAAQ,EACf,SAAS,GAAG,QAAQ,EACpB,iBAAiB,KAEf,KAAK,EADJ,IAAI,UACL,KAAK,EAdH,sJAcL,CAAQ,CAAA;IACT,MAAM,QAAQ,GAAG,MAAM,IAAI,SAAS,KAAK,MAAM,CAAA;IAC/C,MAAM,SAAS,GAAG,YAAY,CAAC,cAAc,CAAC,CAAA;IAC9C,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAE3C,OAAO,CACL,oBAAC,SAAS,oBACJ,IAAI,IACR,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,OAAO,CAChB,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EACzD,SAAS,CACV,EACD,KAAK,EAAE,KAAK;QAEZ,8BACE,SAAS,EACP,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC;YAG9D,kBAAkB,KAAK,UAAU,IAAI,CACpC,8BAAM,SAAS,EAAC,sCAAsC,QAAS,CAChE;YAEA,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ;YAE5C,kBAAkB,KAAK,UAAU,IAAI,aAAa;YAElD,iBAAiB,CACb,CACG,CACb,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,SAAS,CAAC,YAAY,GAAG;IACvB,EAAE,EAAE,OAAO;IACX,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,QAAQ;CACf,CAAA;AAED,SAAS,CAAC,WAAW,GAAG,WAAW,CAAA;AAEnC,eAAe,SAAS,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { OmitInternalProps } from '@toptal/picasso-shared';
2
- import type { Props } from './FormLabel';
3
- export { default as FormLabel } from './FormLabel';
4
- export type { RequiredDecoration } from './FormLabel';
5
- export declare type FormLabelProps = OmitInternalProps<Props>;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/FormLabel/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AAClD,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,oBAAY,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export { default as FormLabel } from './FormLabel';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/FormLabel/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA"}
@@ -1,12 +0,0 @@
1
- import type { FieldLayout } from '../FieldsLayout/FieldsLayoutContext';
2
- import type { Alignment, Size } from './FormLabel';
3
- export declare const classesBySize: Record<Size, string>;
4
- declare type GetRootClassesOptions = {
5
- disabled?: boolean;
6
- isInline: boolean;
7
- layout: FieldLayout;
8
- alignment: Alignment;
9
- };
10
- export declare const getRootClasses: ({ disabled, isInline, layout, alignment, }: GetRootClassesOptions) => string;
11
- export {};
12
- //# sourceMappingURL=styles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/FormLabel/styles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAG9C,CAAA;AAED,aAAK,qBAAqB,GAAG;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,WAAW,CAAA;IACnB,SAAS,EAAE,SAAS,CAAA;CACrB,CAAA;AAqCD,eAAO,MAAM,cAAc,+CAKxB,qBAAqB,WAQvB,CAAA"}
@@ -1,24 +0,0 @@
1
- import { twJoin } from '@toptal/picasso-tailwind-merge';
2
- export const classesBySize = {
3
- medium: 'text-[0.875rem]',
4
- large: 'text-[1rem]',
5
- };
6
- const getDisplayClasses = ({ isInline, layout, alignment, }) => {
7
- if (layout === 'horizontal' && alignment === 'top') {
8
- return 'flex items-start';
9
- }
10
- if (layout === 'horizontal') {
11
- return 'flex items-center';
12
- }
13
- if (isInline) {
14
- return 'inline-block';
15
- }
16
- return 'block';
17
- };
18
- const getMarginClasses = ({ layout, isInline, }) => layout === 'horizontal' || isInline ? 'mb-0' : 'mb-[0.5em]';
19
- const getPaddingsClasses = ({ layout, alignment, }) => layout === 'horizontal' && alignment === 'top' ? 'pt-2' : '';
20
- const getColorClasses = ({ disabled }) => disabled ? 'text-graphite-700/[0.48]' : 'text-graphite-700';
21
- export const getRootClasses = ({ disabled, isInline, layout, alignment, }) => {
22
- return twJoin(getDisplayClasses({ isInline, layout, alignment }), 'leading-[1em]', getMarginClasses({ layout, isInline }), getColorClasses({ disabled }), getPaddingsClasses({ layout, alignment }));
23
- };
24
- //# sourceMappingURL=styles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/FormLabel/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAKvD,MAAM,CAAC,MAAM,aAAa,GAAyB;IACjD,MAAM,EAAE,iBAAiB;IACzB,KAAK,EAAE,aAAa;CACrB,CAAA;AASD,MAAM,iBAAiB,GAAG,CAAC,EACzB,QAAQ,EACR,MAAM,EACN,SAAS,GACsB,EAAE,EAAE;IACnC,IAAI,MAAM,KAAK,YAAY,IAAI,SAAS,KAAK,KAAK,EAAE;QAClD,OAAO,kBAAkB,CAAA;KAC1B;IAED,IAAI,MAAM,KAAK,YAAY,EAAE;QAC3B,OAAO,mBAAmB,CAAA;KAC3B;IAED,IAAI,QAAQ,EAAE;QACZ,OAAO,cAAc,CAAA;KACtB;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,EACxB,MAAM,EACN,QAAQ,GACuB,EAAE,EAAE,CACnC,MAAM,KAAK,YAAY,IAAI,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAA;AAE7D,MAAM,kBAAkB,GAAG,CAAC,EAC1B,MAAM,EACN,SAAS,GACsB,EAAE,EAAE,CACnC,MAAM,KAAK,YAAY,IAAI,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;AAE9D,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAkC,EAAE,EAAE,CACvE,QAAQ,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,mBAAmB,CAAA;AAE7D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,GACa,EAAE,EAAE;IAC1B,OAAO,MAAM,CACX,iBAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAClD,eAAe,EACf,gBAAgB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EACtC,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,EAC7B,kBAAkB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAC1C,CAAA;AACH,CAAC,CAAA"}
@@ -1,53 +0,0 @@
1
- import React, { createContext, useContext, useMemo } from 'react'
2
- import { useBreakpoint } from '@toptal/picasso-utils'
3
- import type { BreakpointKeys } from '@toptal/picasso-utils'
4
-
5
- export type LabelColumnSize = 2 | 3 | 4
6
-
7
- export type ResponsiveLabelColumnSize = {
8
- [k in BreakpointKeys]?: LabelColumnSize
9
- }
10
-
11
- export type FieldLayout = 'horizontal' | 'vertical'
12
-
13
- export type FieldsLayoutContextValue = {
14
- layout: FieldLayout
15
- labelWidth: LabelColumnSize | ResponsiveLabelColumnSize
16
- }
17
-
18
- export const DEFAULT_LABEL_WIDTH_SIZE: LabelColumnSize = 3
19
-
20
- const FieldsLayoutContext = createContext<FieldsLayoutContextValue>({
21
- layout: 'vertical',
22
- labelWidth: DEFAULT_LABEL_WIDTH_SIZE,
23
- })
24
-
25
- export type FieldsLayoutContextProviderProps = {
26
- layout?: FieldLayout
27
- labelWidth?: LabelColumnSize | ResponsiveLabelColumnSize
28
- children: React.ReactNode
29
- }
30
-
31
- export const FieldsLayoutContextProvider = ({
32
- layout = 'vertical',
33
- labelWidth = DEFAULT_LABEL_WIDTH_SIZE,
34
- children,
35
- }: FieldsLayoutContextProviderProps) => {
36
- const isSmallScreen = useBreakpoint(['sm', 'xs'])
37
-
38
- const value = useMemo(
39
- () => ({
40
- layout: isSmallScreen ? 'vertical' : layout,
41
- labelWidth,
42
- }),
43
- [layout, isSmallScreen, labelWidth]
44
- )
45
-
46
- return (
47
- <FieldsLayoutContext.Provider value={value}>
48
- {children}
49
- </FieldsLayoutContext.Provider>
50
- )
51
- }
52
-
53
- export const useFieldsLayoutContext = () => useContext(FieldsLayoutContext)
@@ -1 +0,0 @@
1
- export * from './FieldsLayoutContext'
@@ -1,84 +0,0 @@
1
- import type { ReactElement, ReactNode, LabelHTMLAttributes } from 'react'
2
- import React, { forwardRef } from 'react'
3
- import type { FormControlLabelProps } from '@material-ui/core/FormControlLabel'
4
- import type { StandardProps, TextLabelProps } from '@toptal/picasso-shared'
5
- import { twMerge } from '@toptal/picasso-tailwind-merge'
6
-
7
- import type { RequiredDecoration } from '../FormLabel'
8
- import { FormCompound as Form } from '../FormCompound'
9
- import { useFieldsLayoutContext } from '../FieldsLayout'
10
-
11
- export type FormControlLabelAttributesType =
12
- LabelHTMLAttributes<HTMLLabelElement> &
13
- Pick<FormControlLabelProps, 'onChange'>
14
-
15
- export interface Props
16
- extends StandardProps,
17
- TextLabelProps,
18
- FormControlLabelAttributesType {
19
- /** A control element. For instance, it can be be a Radio or a Checkbox */
20
- control: ReactElement
21
- /** The text to be used in an enclosing label element */
22
- label?: ReactNode
23
- /** Shows whether label is disabled or not */
24
- disabled?: boolean
25
- /** Whether to show asterisk or (optional) postfix as a 'required' decoration */
26
- requiredDecoration?: RequiredDecoration
27
- classes?: {
28
- root?: string
29
- label?: string
30
- }
31
- }
32
-
33
- const FormControlLabel = forwardRef<HTMLLabelElement, Props>(
34
- function FormControlLabel(props, ref) {
35
- const {
36
- control,
37
- label,
38
- className,
39
- style,
40
- disabled,
41
- requiredDecoration,
42
- titleCase,
43
- classes,
44
- ...rest
45
- } = props
46
-
47
- const { layout } = useFieldsLayoutContext()
48
- const isHorizontalLayout = layout === 'horizontal'
49
-
50
- return (
51
- <label
52
- {...rest}
53
- ref={ref}
54
- className={twMerge(
55
- 'inline-flex items-center',
56
- 'max-w-full',
57
- 'align-middle',
58
- '-webkit-tap-highlight-color-transparent',
59
- 'mx-0',
60
- disabled ? 'cursor-default' : 'cursor-pointer',
61
- isHorizontalLayout && 'col-start-1 col-span-2',
62
- classes?.root,
63
- className
64
- )}
65
- style={style}
66
- >
67
- {React.cloneElement(control, { disabled })}
68
- <Form.Label
69
- className={twMerge(disabled && 'pointer-events-auto', classes?.label)}
70
- as='span'
71
- requiredDecoration={requiredDecoration}
72
- disabled={disabled}
73
- titleCase={titleCase}
74
- >
75
- {label}
76
- </Form.Label>
77
- </label>
78
- )
79
- }
80
- )
81
-
82
- FormControlLabel.displayName = 'FormControlLabel'
83
-
84
- export default FormControlLabel
@@ -1,6 +0,0 @@
1
- import type { OmitInternalProps } from '@toptal/picasso-shared'
2
-
3
- import type { Props } from './FormControlLabel'
4
-
5
- export { default as FormControlLabel } from './FormControlLabel'
6
- export type FormControlLabelProps = OmitInternalProps<Props>
@@ -1,106 +0,0 @@
1
- import type { HTMLAttributes, ReactNode } from 'react'
2
- import React, { forwardRef } from 'react'
3
- import type {
4
- BaseProps,
5
- TextLabelProps,
6
- SizeType,
7
- } from '@toptal/picasso-shared'
8
- import { useTitleCase } from '@toptal/picasso-shared'
9
- import { toTitleCase } from '@toptal/picasso-utils'
10
- import { twMerge } from '@toptal/picasso-tailwind-merge'
11
-
12
- import { classesBySize, getRootClasses } from './styles'
13
- import { useFieldsLayoutContext } from '../FieldsLayout'
14
-
15
- type ComponentType = 'label' | 'span'
16
- export type RequiredDecoration = 'asterisk' | 'optional'
17
-
18
- export type Size = SizeType<'medium' | 'large'>
19
- export type Alignment = 'top' | 'middle'
20
-
21
- export interface Props
22
- extends BaseProps,
23
- TextLabelProps,
24
- HTMLAttributes<HTMLLabelElement | HTMLSpanElement> {
25
- /** Content of the label */
26
- children: ReactNode
27
- /** Whether to show asterisk or (optional) postfix as a 'required' decoration */
28
- requiredDecoration?: RequiredDecoration
29
- /** Is this label for disabled input or not */
30
- disabled?: boolean
31
- /** Specifies an id of the input */
32
- htmlFor?: string
33
- /** Whether label should act as inline element `display: inline-block` */
34
- inline?: boolean
35
- /** Component used for the root node */
36
- as?: ComponentType
37
- /** Component size */
38
- size?: Size
39
- /** Whether label should be aligned to top of the container or not */
40
- alignment?: Alignment
41
- /** Label's end adornment */
42
- labelEndAdornment?: ReactNode
43
- }
44
-
45
- export const FormLabel = forwardRef<HTMLLabelElement, Props>(function FormLabel(
46
- props,
47
- ref
48
- ) {
49
- const {
50
- children,
51
- disabled,
52
- htmlFor,
53
- className,
54
- style,
55
- inline,
56
- as: Component = 'label',
57
- titleCase: propsTitleCase,
58
- requiredDecoration,
59
- size = 'medium',
60
- alignment = 'middle',
61
- labelEndAdornment,
62
- ...rest
63
- } = props
64
- const isInline = inline || Component === 'span'
65
- const titleCase = useTitleCase(propsTitleCase)
66
- const { layout } = useFieldsLayoutContext()
67
-
68
- return (
69
- <Component
70
- {...rest}
71
- ref={ref}
72
- htmlFor={htmlFor}
73
- className={twMerge(
74
- getRootClasses({ disabled, isInline, layout, alignment }),
75
- className
76
- )}
77
- style={style}
78
- >
79
- <span
80
- className={
81
- isInline ? 'align-top text-[0.8125rem]' : classesBySize[size]
82
- }
83
- >
84
- {requiredDecoration === 'asterisk' && (
85
- <span className='align-top text-red-500 mr-[0.3125em]'>*</span>
86
- )}
87
-
88
- {titleCase ? toTitleCase(children) : children}
89
-
90
- {requiredDecoration === 'optional' && ' (optional)'}
91
-
92
- {labelEndAdornment}
93
- </span>
94
- </Component>
95
- )
96
- })
97
-
98
- FormLabel.defaultProps = {
99
- as: 'label',
100
- inline: false,
101
- size: 'medium',
102
- }
103
-
104
- FormLabel.displayName = 'FormLabel'
105
-
106
- export default FormLabel