Skip to content

Commit c86fd60

Browse files
committed
refactor(bem): replace Block/Elem with cn() in Choice.jsx
Migrated Choice tag component from Block/Elem to cn() helper. - Replaced Block/Elem imports with cn import, added React import - Replaced <Block name="choice"> with <div className={cn("choice")...}> - Replaced <Elem name="item"> with <div className={cn("choice").elem("item")...}> - Replaced <Elem name="checkbox" component={nameWrapper(...)}> with extracted CheckboxComponent - Replaced <Elem name="toggle" component={Button}> with <Button className={...}> - Replaced <Elem name="children"> with <div className={cn("choice").elem("children")...}> - Extracted nameWrapper result to const for clarity - Nested Elems within item all use Block "choice" - Preserved mods, styles, handlers, and all props - No behavior change, equivalent class strings Note: Elem "item" under Block "choice" generates dm-choice__item (different from dm-textarea-tag__item in TextAreaRegionView.jsx - no CSS conflict)
1 parent 0c49fc0 commit c86fd60

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

web/libs/editor/src/tags/control/Choice.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import Types from "../../core/Types";
1111
import { AnnotationMixin } from "../../mixins/AnnotationMixin";
1212
import { TagParentMixin } from "../../mixins/TagParentMixin";
1313
import { FF_DEV_3391, isFF } from "../../utils/feature-flags";
14-
import { Block, Elem } from "../../utils/bem";
14+
import { cn } from "../../utils/bem";
1515
import "./Choice/Choice.scss";
1616
import { IconChevron } from "@humansignal/ui";
1717
import { HintTooltip } from "../../components/Taxonomy/Taxonomy";
1818
import { sanitizeHtml } from "../../utils/html";
19+
import React from "react";
1920

2021
/**
2122
* The `Choice` tag represents a single choice for annotations. Use with the `Choices` tag or `Taxonomy` tag to provide specific choice options.
@@ -194,16 +195,15 @@ const HtxNewChoiceView = ({ item, store }) => {
194195
const [collapsed, setCollapsed] = useState(false);
195196
const toogleCollapsed = useCallback(() => setCollapsed((collapsed) => !collapsed), []);
196197

198+
const CheckboxComponent = nameWrapper(item.isCheckbox ? Checkbox : Radio, item._value);
199+
197200
return (
198-
<Block
199-
name="choice"
200-
mod={{ layout: item.parent.layout, leaf: item.isLeaf, notLeaf: !item.isLeaf, hidden: !item.visible }}
201+
<div
202+
className={cn("choice").mod({ layout: item.parent.layout, leaf: item.isLeaf, notLeaf: !item.isLeaf, hidden: !item.visible }).toClassName()}
201203
>
202-
<Elem name="item" mod={{ notLeaf: !item.isLeaf }} style={style}>
203-
<Elem
204-
name="checkbox"
205-
component={nameWrapper(item.isCheckbox ? Checkbox : Radio, item._value)}
206-
mod={{ notLeaf: !item.isLeaf }}
204+
<div className={cn("choice").elem("item").mod({ notLeaf: !item.isLeaf }).toClassName()} style={style}>
205+
<CheckboxComponent
206+
className={cn("choice").elem("checkbox").mod({ notLeaf: !item.isLeaf }).toClassName()}
207207
checked={item.sel}
208208
indeterminate={!item.sel && item.indeterminate}
209209
disabled={item.isReadOnly()}
@@ -213,21 +213,25 @@ const HtxNewChoiceView = ({ item, store }) => {
213213
{item.html ? <span dangerouslySetInnerHTML={{ __html: sanitizeHtml(item.html) }} /> : item._value}
214214
{showHotkey && <Hint>[{item.hotkey}]</Hint>}
215215
</HintTooltip>
216-
</Elem>
216+
</CheckboxComponent>
217217
{!item.isLeaf ? (
218-
<Elem name="toggle" mod={{ collapsed }} component={Button} type="text" onClick={toogleCollapsed}>
218+
<Button
219+
className={cn("choice").elem("toggle").mod({ collapsed }).toClassName()}
220+
type="text"
221+
onClick={toogleCollapsed}
222+
>
219223
<IconChevron />
220-
</Elem>
224+
</Button>
221225
) : (
222226
false
223227
)}
224-
</Elem>
228+
</div>
225229
{item.nestedResults && item.children?.length ? (
226-
<Elem name="children" mod={{ collapsed }}>
230+
<div className={cn("choice").elem("children").mod({ collapsed }).toClassName()}>
227231
{Tree.renderChildren(item, item.annotation)}
228-
</Elem>
232+
</div>
229233
) : null}
230-
</Block>
234+
</div>
231235
);
232236
};
233237

0 commit comments

Comments
 (0)