goobs-frontend 0.8.2 → 0.8.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goobs-frontend",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "A comprehensive React-based UI library built on Material-UI, offering a wide range of customizable components including grids, typography, buttons, cards, forms, navigation, pricing tables, steppers, tooltips, accordions, and more. Designed for building responsive and consistent user interfaces with advanced features like form validation, theming, and code syntax highlighting.",
5
5
  "license": "MIT",
6
6
  "main": "./src/index.ts",
@@ -6,70 +6,35 @@ import {
6
6
  InputLabel,
7
7
  SelectProps,
8
8
  FormHelperText,
9
+ Typography,
9
10
  } from '@mui/material'
10
11
  import { styled } from '@mui/material/styles'
11
12
 
12
- export interface DropdownOption {
13
+ export interface SimpleDropdownOption {
13
14
  value: string
14
- label: string
15
15
  }
16
16
 
17
+ export interface ComplexDropdownOption extends SimpleDropdownOption {
18
+ attribute1?: string
19
+ attribute2?: string
20
+ }
21
+
22
+ export type DropdownOption = SimpleDropdownOption | ComplexDropdownOption
23
+
17
24
  export interface DropdownProps extends Omit<SelectProps, 'onChange'> {
18
- /**
19
- * The label for the dropdown.
20
- */
21
25
  label: string
22
- /**
23
- * The options for the dropdown.
24
- */
25
26
  options: DropdownOption[]
26
- /**
27
- * The default value for the dropdown.
28
- */
29
27
  defaultValue?: string
30
- /**
31
- * The background color of the dropdown.
32
- */
33
28
  backgroundcolor?: string
34
- /**
35
- * The outline color of the dropdown.
36
- */
37
29
  outlinecolor?: string
38
- /**
39
- * The font color of the dropdown.
40
- */
41
30
  fontcolor?: string
42
- /**
43
- * The font color of the dropdown label when shrunk.
44
- */
45
31
  shrunkfontcolor?: string
46
- /**
47
- * Callback function triggered when the dropdown value changes.
48
- */
49
32
  onChange?: SelectProps['onChange']
50
- /**
51
- * Indicates if the dropdown is in an error state.
52
- */
53
33
  error?: boolean
54
- /**
55
- * The helper text to display below the dropdown.
56
- */
57
34
  helperText?: string
58
- /**
59
- * The name of the dropdown.
60
- */
61
35
  name?: string
62
- /**
63
- * Indicates if the dropdown is required.
64
- */
65
36
  required?: boolean
66
- /**
67
- * Callback function triggered when the dropdown loses focus.
68
- */
69
37
  onBlur?: SelectProps['onBlur']
70
- /**
71
- * Callback function triggered when the dropdown receives focus.
72
- */
73
38
  onFocus?: SelectProps['onFocus']
74
39
  }
75
40
 
@@ -100,9 +65,16 @@ const StyledInputLabel = styled(InputLabel)<{ shrunkfontcolor?: string }>(
100
65
  })
101
66
  )
102
67
 
103
- /**
104
- * Dropdown component built with Material UI.
105
- */
68
+ const StyledMenuItem = styled(MenuItem)(({ theme }) => ({
69
+ display: 'flex',
70
+ flexDirection: 'column',
71
+ alignItems: 'flex-start',
72
+ }))
73
+
74
+ const capitalizeFirstLetter = (string: string) => {
75
+ return string.charAt(0).toUpperCase() + string.slice(1)
76
+ }
77
+
106
78
  const Dropdown: React.FC<DropdownProps> = ({
107
79
  label,
108
80
  options,
@@ -139,6 +111,27 @@ const Dropdown: React.FC<DropdownProps> = ({
139
111
  onFocus?.(event)
140
112
  }
141
113
 
114
+ const renderMenuItem = (option: DropdownOption) => {
115
+ const label = capitalizeFirstLetter(option.value.replace(/_/g, ' '))
116
+ if (!('attribute1' in option)) {
117
+ return (
118
+ <MenuItem key={option.value} value={option.value}>
119
+ {label}
120
+ </MenuItem>
121
+ )
122
+ } else {
123
+ return (
124
+ <StyledMenuItem key={option.value} value={option.value}>
125
+ <Typography variant="body1">{label}</Typography>
126
+ <Typography variant="caption" color="textSecondary">
127
+ {option.attribute1}
128
+ {option.attribute2 && ` | ${option.attribute2}`}
129
+ </Typography>
130
+ </StyledMenuItem>
131
+ )
132
+ }
133
+ }
134
+
142
135
  return (
143
136
  <StyledFormControl
144
137
  backgroundcolor={backgroundcolor}
@@ -161,11 +154,7 @@ const Dropdown: React.FC<DropdownProps> = ({
161
154
  aria-labelledby={`${name}-label`}
162
155
  {...rest}
163
156
  >
164
- {options.map(option => (
165
- <MenuItem key={option.value} value={option.value}>
166
- {option.label}
167
- </MenuItem>
168
- ))}
157
+ {options.map(renderMenuItem)}
169
158
  </Select>
170
159
  {helperText && <FormHelperText>{helperText}</FormHelperText>}
171
160
  </StyledFormControl>