@zesty-io/material 0.0.4 → 0.1.2
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.
- package/es/ConfirmDialog/ConfirmDialog.stories.d.ts +6 -0
- package/es/ConfirmDialog/ConfirmDialog.stories.js +24 -0
- package/es/ConfirmDialog/index.d.ts +18 -0
- package/es/ConfirmDialog/index.js +11 -0
- package/es/ConfirmModal/ConfirmModal.stories.d.ts +6 -0
- package/es/ConfirmModal/ConfirmModal.stories.js +24 -0
- package/es/ConfirmModal/index.d.ts +18 -0
- package/es/ConfirmModal/index.js +11 -0
- package/es/CopyButton/index.js +3 -3
- package/es/FieldTypeColor/FieldTypeColor.stories.d.ts +5 -0
- package/es/FieldTypeColor/FieldTypeColor.stories.js +21 -0
- package/es/FieldTypeColor/index.d.ts +6 -0
- package/es/FieldTypeColor/index.js +16 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.d.ts +5 -0
- package/es/FieldTypeDate/FieldTypeDate.stories.js +17 -0
- package/es/FieldTypeDate/index.d.ts +9 -0
- package/es/FieldTypeDate/index.js +10 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.d.ts +5 -0
- package/es/FieldTypeDateTime/FieldTypeDateTime.stories.js +17 -0
- package/es/FieldTypeDateTime/index.d.ts +9 -0
- package/es/FieldTypeDateTime/index.js +10 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.d.ts +5 -0
- package/es/FieldTypeDropdown/FieldTypeDropwdon.stories.js +35 -0
- package/es/FieldTypeDropdown/index.d.ts +11 -0
- package/es/FieldTypeDropdown/index.js +10 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.d.ts +5 -0
- package/es/FieldTypeNumber/FieldTypeNumber.stories.js +21 -0
- package/es/FieldTypeNumber/index.d.ts +6 -0
- package/es/FieldTypeNumber/index.js +7 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.d.ts +5 -0
- package/es/FieldTypeOneToMany/FieldTypeOneToMany.stories.js +28 -0
- package/es/FieldTypeOneToMany/index.d.ts +32 -0
- package/es/FieldTypeOneToMany/index.js +29 -0
- package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.d.ts +5 -0
- package/es/FieldTypeOneToOne/FieldTypeOneToOne.stories.js +28 -0
- package/es/FieldTypeOneToOne/index.d.ts +34 -0
- package/es/FieldTypeOneToOne/index.js +33 -0
- package/es/FieldTypeSort/FieldTypeSort.stories.js +3 -1
- package/es/FieldTypeSort/index.d.ts +1 -1
- package/es/FieldTypeSort/index.js +17 -29
- package/es/FieldTypeText/FieldTypeText.stories.js +6 -6
- package/es/FieldTypeText/index.d.ts +1 -1
- package/es/FieldTypeText/index.js +4 -12
- package/es/FieldTypeUrl/index.d.ts +1 -1
- package/es/FieldTypeUrl/index.js +8 -16
- package/es/index.d.ts +11 -0
- package/es/index.js +11 -0
- package/es/theme/index.js +13 -2
- package/es/utils/virtualization.d.ts +2 -0
- package/es/utils/virtualization.js +63 -0
- package/package.json +7 -3
- package/src/ConfirmDialog/ConfirmDialog.stories.tsx +35 -0
- package/src/ConfirmDialog/index.tsx +50 -0
- package/src/CopyButton/index.tsx +6 -6
- package/src/FieldTypeColor/FieldTypeColor.stories.tsx +35 -0
- package/src/FieldTypeColor/index.tsx +43 -0
- package/src/FieldTypeDate/FieldTypeDate.stories.tsx +23 -0
- package/src/FieldTypeDate/index.tsx +34 -0
- package/src/FieldTypeDateTime/FieldTypeDateTime.stories.tsx +23 -0
- package/src/FieldTypeDateTime/index.tsx +35 -0
- package/src/FieldTypeDropdown/FieldTypeDropwdon.stories.tsx +52 -0
- package/src/FieldTypeDropdown/index.tsx +41 -0
- package/src/FieldTypeNumber/FieldTypeNumber.stories.tsx +35 -0
- package/src/FieldTypeNumber/index.tsx +22 -0
- package/src/FieldTypeOneToMany/FieldTypeOneToMany.stories.tsx +47 -0
- package/src/FieldTypeOneToMany/index.tsx +90 -0
- package/src/FieldTypeOneToOne/FieldTypeOneToOne.stories.tsx +46 -0
- package/src/FieldTypeOneToOne/index.tsx +96 -0
- package/src/FieldTypeSort/FieldTypeSort.stories.tsx +3 -2
- package/src/FieldTypeSort/index.tsx +15 -68
- package/src/FieldTypeText/FieldTypeText.stories.tsx +11 -9
- package/src/FieldTypeText/index.tsx +11 -19
- package/src/FieldTypeUrl/index.tsx +12 -19
- package/src/index.ts +11 -0
- package/src/theme/index.ts +15 -2
- package/src/utils/virtualization.tsx +107 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useRef } from 'react';
|
|
2
2
|
import MuiTextField, { OutlinedTextFieldProps } from '@mui/material/TextField';
|
|
3
|
-
import {
|
|
3
|
+
import { FormControl, FormLabel, Box } from '@mui/material';
|
|
4
4
|
|
|
5
5
|
export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
6
6
|
/**
|
|
@@ -11,39 +11,32 @@ export interface FieldTypeUrlProps extends Omit<OutlinedTextFieldProps, 'variant
|
|
|
11
11
|
value: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const FieldTypeUrl = ({maxLength = 2000, value, helperText,
|
|
14
|
+
const FieldTypeUrl = ({label, maxLength = 2000, value, helperText, required, inputProps, ...props }: FieldTypeUrlProps) => {
|
|
15
15
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
|
+
<FormControl fullWidth required={required}>
|
|
19
|
+
{/* Sets flex order to make appended required asterisk properly positioned */}
|
|
20
|
+
<FormLabel sx={{display: 'flex', justifyContent: 'space-between', '& .MuiFormLabel-asterisk': {order: 2}}}>
|
|
21
|
+
<Box sx={{ order: 1}}>{label}</Box>
|
|
22
|
+
<Box sx={{ order: 3, flex: 1, textAlign: 'right'}}>{value?.length}/{maxLength}</Box>
|
|
23
|
+
</FormLabel>
|
|
18
24
|
<MuiTextField
|
|
19
25
|
size="small"
|
|
20
26
|
type='url'
|
|
21
27
|
variant='outlined'
|
|
22
28
|
value={value}
|
|
23
|
-
InputProps={{
|
|
24
|
-
endAdornment: (
|
|
25
|
-
<InputAdornment position="end">
|
|
26
|
-
<>{value.length}/{maxLength}</>
|
|
27
|
-
</InputAdornment>
|
|
28
|
-
),
|
|
29
|
-
// Spread props at the end to allow Input prop overrides
|
|
30
|
-
...InputProps,
|
|
31
|
-
}}
|
|
32
|
-
InputLabelProps={{
|
|
33
|
-
shrink: true,
|
|
34
|
-
// Spread props at the end to allow InputLabel prop overrides
|
|
35
|
-
...InputLabelProps,
|
|
36
|
-
}}
|
|
37
29
|
inputProps={{
|
|
38
30
|
ref: inputRef,
|
|
39
31
|
// Spread props at the end to allow inputProps prop overrides
|
|
40
32
|
...inputProps,
|
|
41
33
|
}}
|
|
42
|
-
error={(value && !inputRef.current?.validity.valid) || value
|
|
43
|
-
helperText={value
|
|
34
|
+
error={(value && !inputRef.current?.validity.valid) || value?.length > maxLength}
|
|
35
|
+
helperText={value?.length > maxLength ? 'Your input is over the specified limit' : (value && !inputRef.current?.validity.valid) ? 'Your input is not a valid url' : helperText}
|
|
44
36
|
// Spread props at the end to allow prop overrides
|
|
45
37
|
{...props}
|
|
46
38
|
/>
|
|
39
|
+
</FormControl>
|
|
47
40
|
);
|
|
48
41
|
};
|
|
49
42
|
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export { default as theme } from './theme';
|
|
2
2
|
export { default as FieldTypeText } from './FieldTypeText';
|
|
3
|
+
export { default as FieldTypeSort } from './FieldTypeSort';
|
|
4
|
+
export { default as FieldTypeUrl } from './FieldTypeUrl';
|
|
5
|
+
export { default as FieldTypeDate } from './FieldTypeDate';
|
|
6
|
+
export { default as FieldTypeDateTime } from './FieldTypeDateTime';
|
|
7
|
+
export { default as FieldTypeColor } from './FieldTypeColor';
|
|
8
|
+
export { default as FieldTypeNumber } from './FieldTypeNumber';
|
|
9
|
+
export { default as FieldTypeDropdown } from './FieldTypeDropdown';
|
|
10
|
+
export { default as FieldTypeOneToOne} from './FieldTypeOneToOne';
|
|
11
|
+
export { default as FieldTypeOneToMany} from './FieldTypeOneToMany';
|
|
12
|
+
export { default as CopyButton } from './CopyButton';
|
|
13
|
+
export { default as ConfirmDialog } from './ConfirmDialog';
|
package/src/theme/index.ts
CHANGED
|
@@ -13,8 +13,8 @@ theme = createTheme(theme, {
|
|
|
13
13
|
styleOverrides: {
|
|
14
14
|
root: {
|
|
15
15
|
minWidth: 'auto',
|
|
16
|
-
}
|
|
17
|
-
}
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
18
|
},
|
|
19
19
|
MuiTooltip: {
|
|
20
20
|
styleOverrides: {
|
|
@@ -36,9 +36,22 @@ theme = createTheme(theme, {
|
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
+
MuiFormLabel: {
|
|
40
|
+
styleOverrides: {
|
|
41
|
+
root: {
|
|
42
|
+
color: theme.palette.primary.dark,
|
|
43
|
+
},
|
|
44
|
+
asterisk: {
|
|
45
|
+
color: theme.palette.error.main,
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
},
|
|
39
49
|
MuiToggleButton: {
|
|
40
50
|
styleOverrides: {
|
|
41
51
|
root: ({ ownerState, theme }: any) => ({
|
|
52
|
+
backgroundColor: `${
|
|
53
|
+
theme.palette[ownerState.color].contrastText
|
|
54
|
+
} !important`,
|
|
42
55
|
...(ownerState.selected && {
|
|
43
56
|
color: `${theme.palette[ownerState.color].contrastText} !important`,
|
|
44
57
|
backgroundColor: `${
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
3
|
+
import ListSubheader from '@mui/material/ListSubheader';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import { VariableSizeList, ListChildComponentProps } from 'react-window';
|
|
6
|
+
import Typography from '@mui/material/Typography';
|
|
7
|
+
|
|
8
|
+
const LISTBOX_PADDING = 8; // px
|
|
9
|
+
|
|
10
|
+
function renderRow(props: ListChildComponentProps) {
|
|
11
|
+
const { data, index, style } = props;
|
|
12
|
+
const dataSet = data[index];
|
|
13
|
+
const inlineStyle = {
|
|
14
|
+
...style,
|
|
15
|
+
top: (style.top as number) + LISTBOX_PADDING,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (dataSet.hasOwnProperty('group')) {
|
|
19
|
+
return (
|
|
20
|
+
<ListSubheader key={dataSet.key} component="div" style={inlineStyle}>
|
|
21
|
+
{dataSet.group}
|
|
22
|
+
</ListSubheader>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Typography component="li" {...dataSet[0]} noWrap style={inlineStyle}>
|
|
28
|
+
{dataSet[1]}
|
|
29
|
+
</Typography>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const OuterElementContext = React.createContext({});
|
|
34
|
+
|
|
35
|
+
const OuterElementType = React.forwardRef<HTMLDivElement>((props, ref) => {
|
|
36
|
+
const outerProps = React.useContext(OuterElementContext);
|
|
37
|
+
return <div ref={ref} {...props} {...outerProps} />;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function useResetCache(data: any) {
|
|
41
|
+
const ref = React.useRef<VariableSizeList>(null);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (ref.current != null) {
|
|
44
|
+
ref.current.resetAfterIndex(0, true);
|
|
45
|
+
}
|
|
46
|
+
}, [data]);
|
|
47
|
+
return ref;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Adapter for react-window
|
|
51
|
+
export const ListboxComponent = React.forwardRef<
|
|
52
|
+
HTMLDivElement,
|
|
53
|
+
React.HTMLAttributes<HTMLElement>
|
|
54
|
+
>(function ListboxComponent(props, ref) {
|
|
55
|
+
const { children, ...other } = props;
|
|
56
|
+
const itemData: React.ReactChild[] = [];
|
|
57
|
+
(children as React.ReactChild[]).forEach(
|
|
58
|
+
(item: React.ReactChild & { children?: React.ReactChild[] }) => {
|
|
59
|
+
itemData.push(item);
|
|
60
|
+
itemData.push(...(item.children || []));
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const theme = useTheme();
|
|
65
|
+
const smUp = useMediaQuery(theme.breakpoints.up('sm'), {
|
|
66
|
+
noSsr: true,
|
|
67
|
+
});
|
|
68
|
+
const itemCount = itemData.length;
|
|
69
|
+
const itemSize = smUp ? 36 : 48;
|
|
70
|
+
|
|
71
|
+
const getChildSize = (child: React.ReactChild) => {
|
|
72
|
+
if (child.hasOwnProperty('group')) {
|
|
73
|
+
return 48;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return itemSize;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getHeight = () => {
|
|
80
|
+
if (itemCount > 8) {
|
|
81
|
+
return 8 * itemSize;
|
|
82
|
+
}
|
|
83
|
+
return itemData.map(getChildSize).reduce((a, b) => a + b, 0);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const gridRef = useResetCache(itemCount);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div ref={ref}>
|
|
90
|
+
<OuterElementContext.Provider value={other}>
|
|
91
|
+
<VariableSizeList
|
|
92
|
+
itemData={itemData}
|
|
93
|
+
height={getHeight() + 2 * LISTBOX_PADDING}
|
|
94
|
+
width="100%"
|
|
95
|
+
ref={gridRef}
|
|
96
|
+
outerElementType={OuterElementType}
|
|
97
|
+
innerElementType="ul"
|
|
98
|
+
itemSize={(index: any) => getChildSize(itemData[index])}
|
|
99
|
+
overscanCount={5}
|
|
100
|
+
itemCount={itemCount}
|
|
101
|
+
>
|
|
102
|
+
{renderRow}
|
|
103
|
+
</VariableSizeList>
|
|
104
|
+
</OuterElementContext.Provider>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
});
|