@toptal/picasso-form-layout 1.0.1

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.
@@ -0,0 +1,20 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export * from './FieldsLayoutContext';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/FieldsLayout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './FieldsLayoutContext';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/FieldsLayout/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export type { FieldsLayoutContextProviderProps, FieldsLayoutContextValue, FieldLayout, LabelColumnSize, ResponsiveLabelColumnSize, } from './FieldsLayout';
2
+ export { useFieldsLayoutContext, FieldsLayoutContextProvider, DEFAULT_LABEL_WIDTH_SIZE, } from './FieldsLayout';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gCAAgC,EAChC,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { useFieldsLayoutContext, FieldsLayoutContextProvider, DEFAULT_LABEL_WIDTH_SIZE, } from './FieldsLayout';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,gBAAgB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@toptal/picasso-form-layout",
3
+ "version": "1.0.1",
4
+ "description": "Toptal UI components library - Form Layout",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "main": "./dist-package/src/index.js",
9
+ "module": "./dist-package/src/index.js",
10
+ "scripts": {
11
+ "build:package": "tsc -b tsconfig.json",
12
+ "prepublishOnly": "yarn build:package"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/toptal/picasso.git"
17
+ },
18
+ "author": "Toptal",
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://github.com/toptal/picasso/issues"
22
+ },
23
+ "homepage": "https://github.com/toptal/picasso/tree/master/packages/picasso#readme",
24
+ "dependencies": {
25
+ "@toptal/picasso-shared": "15.0.0",
26
+ "@toptal/picasso-utils": "3.0.0",
27
+ "ap-style-title-case": "^1.1.2"
28
+ },
29
+ "sideEffects": [
30
+ "**/styles.ts",
31
+ "**/styles.js"
32
+ ],
33
+ "peerDependencies": {
34
+ "@material-ui/core": "4.12.4",
35
+ "@toptal/picasso-tailwind": ">=2.7",
36
+ "@toptal/picasso-tailwind-merge": "^2.0.0",
37
+ "react": ">=16.12.0 < 19.0.0"
38
+ },
39
+ "exports": {
40
+ ".": "./dist-package/src/index.js"
41
+ },
42
+ "devDependencies": {
43
+ "@toptal/picasso-tailwind-merge": "2.0.2",
44
+ "@toptal/picasso-test-utils": "1.1.1"
45
+ },
46
+ "files": [
47
+ "dist-package/**",
48
+ "!dist-package/tsconfig.tsbuildinfo",
49
+ "src"
50
+ ]
51
+ }
@@ -0,0 +1,53 @@
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)
@@ -0,0 +1 @@
1
+ export * from './FieldsLayoutContext'
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export type {
2
+ FieldsLayoutContextProviderProps,
3
+ FieldsLayoutContextValue,
4
+ FieldLayout,
5
+ LabelColumnSize,
6
+ ResponsiveLabelColumnSize,
7
+ } from './FieldsLayout'
8
+ export {
9
+ useFieldsLayoutContext,
10
+ FieldsLayoutContextProvider,
11
+ DEFAULT_LABEL_WIDTH_SIZE,
12
+ } from './FieldsLayout'