MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / WeekDaysPicker

Function WeekDaysPicker

packages/ui/src/ui-component/picker/WeekDaysPicker.jsx:16–81  ·  view source on GitHub ↗
({ value, options, onChange, disabled = false })

Source from the content-addressed store, hash-verified

14]
15
16export const WeekDaysPicker = ({ value, options, onChange, disabled = false }) => {
17 const theme = useTheme()
18 const days = options?.length ? options.map((o) => ({ label: o.label, value: o.name })) : DEFAULT_DAYS
19
20 const parseValue = (val) => {
21 if (!val) return []
22 if (Array.isArray(val)) return val
23 if (typeof val === 'string')
24 return val
25 .split(',')
26 .map((token) => token.trim())
27 .filter(Boolean)
28 return []
29 }
30
31 const [selected, setSelected] = useState(parseValue(value))
32
33 useEffect(() => {
34 setSelected(parseValue(value))
35 }, [value])
36
37 const toggle = (dayValue) => {
38 if (disabled) return
39 let next
40 if (selected.includes(dayValue)) {
41 next = selected.filter((d) => d !== dayValue)
42 } else {
43 next = [...selected, dayValue]
44 }
45 // Sort by the days array order
46 next.sort((a, b) => days.findIndex((d) => d.value === a) - days.findIndex((d) => d.value === b))
47 setSelected(next)
48 onChange(next.join(','))
49 }
50
51 return (
52 <Box sx={{ mt: 1, display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
53 {days.map((day) => {
54 const isSelected = selected.includes(day.value)
55 return (
56 <Chip
57 key={day.value}
58 label={day.label}
59 size='small'
60 disabled={disabled}
61 onClick={() => toggle(day.value)}
62 sx={{
63 cursor: disabled ? 'default' : 'pointer',
64 fontWeight: isSelected ? 600 : 400,
65 borderWidth: '1.5px',
66 borderStyle: 'solid',
67 borderColor: isSelected ? theme.palette.primary.main : theme.palette.grey[400],
68 backgroundColor: isSelected ? theme.palette.primary.main + '20' : 'transparent',
69 color: isSelected ? theme.palette.primary.main : theme.palette.text.primary,
70 '&:hover': disabled
71 ? {}
72 : {
73 backgroundColor: isSelected ? theme.palette.primary.main + '35' : theme.palette.grey[200]

Callers

nothing calls this directly

Calls 2

parseValueFunction · 0.70
toggleFunction · 0.70

Tested by

no test coverage detected