Skip to content

Commit 8438007

Browse files
committed
refactor checklist portion of dropdown into its own optionlist; implement checklist component
1 parent 31807a1 commit 8438007

File tree

9 files changed

+402
-294
lines changed

9 files changed

+402
-294
lines changed

components/dash-core-components/src/components/Checklist.react.js

Lines changed: 0 additions & 230 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, {useMemo} from 'react';
2+
import {append, includes, without} from 'ramda';
3+
import {ChecklistProps, PersistedProps, PersistenceTypes} from '../types';
4+
import './css/checklist.css';
5+
6+
import {sanitizeOptions} from '../utils/optionTypes';
7+
import LoadingElement from '../utils/_LoadingElement';
8+
import {Option, OptionsList} from '../utils/optionRendering';
9+
10+
/**
11+
* Checklist is a component that encapsulates several checkboxes.
12+
* The values and labels of the checklist are specified in the `options`
13+
* property and the checked items are specified with the `value` property.
14+
* Each checkbox is rendered as an input with a surrounding label.
15+
*/
16+
export default function Checklist({
17+
className,
18+
id,
19+
style,
20+
setProps,
21+
inputStyle = {},
22+
inputClassName = '',
23+
labelStyle = {},
24+
labelClassName = '',
25+
options = [],
26+
value = [],
27+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
28+
persisted_props = [PersistedProps.value],
29+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
30+
persistence_type = PersistenceTypes.local,
31+
inline = false,
32+
}: ChecklistProps) {
33+
const sanitizedOptions = useMemo(() => {
34+
return sanitizeOptions(options);
35+
}, [options]);
36+
37+
const stylingProps = {
38+
id,
39+
className: 'dash-checklist ' + (className ?? ''),
40+
style,
41+
optionClassName: inline ? 'dash-checklist-inline' : undefined,
42+
inputStyle,
43+
inputClassName,
44+
labelStyle,
45+
labelClassName,
46+
};
47+
48+
return (
49+
<LoadingElement>
50+
{loadingProps => (
51+
<OptionsList
52+
{...loadingProps}
53+
options={sanitizedOptions}
54+
selected={value ?? []}
55+
onSelectionChange={selection => {
56+
setProps({value: selection});
57+
}}
58+
{...stylingProps}
59+
/>
60+
)}
61+
</LoadingElement>
62+
);
63+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.dash-options-list-option.dash-checklist-inline {
2+
display: inline-block;
3+
margin-right: calc(var(--Dash-Spacing) * 4);
4+
}

components/dash-core-components/src/components/css/dropdown.css

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -191,40 +191,5 @@
191191

192192
.dash-dropdown-option {
193193
padding: var(--Dash-Spacing) calc(var(--Dash-Spacing) * 3);
194-
background: var(--Dash-Fill-Inverse-strong);
195194
box-shadow: 0 -1px 0 0 var(--Dash-Fill-Disabled) inset;
196-
color: var(--Dash-Text-Strong);
197-
cursor: pointer;
198-
display: flex;
199-
align-items: center;
200-
user-select: none;
201-
overflow: hidden;
202-
}
203-
204-
.dash-dropdown-option:not(:has(input[disabled])):hover,
205-
.dash-dropdown-option:not(:has(input[disabled])):focus-within {
206-
color: var(--Dash-Fill-Interactive-Strong);
207-
background: var(--Dash-Fill-Interactive-Weak);
208-
}
209-
210-
.dash-dropdown-option:has(input[disabled]) {
211-
color: var(--Dash-Text-Disabled);
212-
cursor: not-allowed;
213-
}
214-
215-
.dash-dropdown-option-text {
216-
white-space: pre;
217-
}
218-
219-
.dash-dropdown-option-checkbox {
220-
display: inline-block;
221-
margin: 0 calc(var(--Dash-Spacing) * 2) 0 0;
222-
box-sizing: border-box;
223-
border: 1px solid var(--Dash-Stroke-Strong);
224-
}
225-
226-
.dash-dropdown-option-checkbox:hover,
227-
.dash-dropdown-option-checkbox:focus,
228-
.dash-dropdown-option-checkbox:checked {
229-
accent-color: var(--Dash-Fill-Interactive-Strong);
230195
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.dash-options-list-option {
2+
padding: var(--Dash-Spacing) 0;
3+
background: var(--Dash-Fill-Inverse-strong);
4+
color: var(--Dash-Text-Strong);
5+
cursor: pointer;
6+
display: flex;
7+
align-items: center;
8+
user-select: none;
9+
overflow: hidden;
10+
}
11+
12+
.dash-options-list-option:not(:has(input[disabled])):hover,
13+
.dash-options-list-option:not(:has(input[disabled])):focus-within {
14+
color: var(--Dash-Fill-Interactive-Strong);
15+
background: var(--Dash-Fill-Interactive-Weak);
16+
}
17+
18+
.dash-options-list-option:has(input[disabled]) {
19+
color: var(--Dash-Text-Disabled);
20+
cursor: not-allowed;
21+
}
22+
23+
.dash-options-list-option-text {
24+
white-space: pre;
25+
}
26+
27+
.dash-options-list-option-text > * {
28+
vertical-align: middle;
29+
}
30+
31+
.dash-options-list-option-checkbox {
32+
display: inline-block;
33+
margin: 0 calc(var(--Dash-Spacing) * 2) 0 0;
34+
box-sizing: border-box;
35+
border: 1px solid var(--Dash-Stroke-Strong);
36+
}
37+
38+
.dash-options-list-option-checkbox:hover,
39+
.dash-options-list-option-checkbox:focus,
40+
.dash-options-list-option-checkbox:checked {
41+
accent-color: var(--Dash-Fill-Interactive-Strong);
42+
}

0 commit comments

Comments
 (0)