Skip to content

Commit 0405195

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) Choice
1 parent 46c1bca commit 0405195

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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";
@@ -194,16 +194,17 @@ const HtxNewChoiceView = ({ item, store }) => {
194194
const [collapsed, setCollapsed] = useState(false);
195195
const toogleCollapsed = useCallback(() => setCollapsed((collapsed) => !collapsed), []);
196196

197+
const CheckboxComponent = nameWrapper(item.isCheckbox ? Checkbox : Radio, item._value);
198+
197199
return (
198-
<Block
199-
name="choice"
200-
mod={{ layout: item.parent.layout, leaf: item.isLeaf, notLeaf: !item.isLeaf, hidden: !item.visible }}
200+
<div
201+
className={cn("choice")
202+
.mod({ layout: item.parent.layout, leaf: item.isLeaf, notLeaf: !item.isLeaf, hidden: !item.visible })
203+
.toClassName()}
201204
>
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 }}
205+
<div className={cn("choice").elem("item").mod({ notLeaf: !item.isLeaf }).toClassName()} style={style}>
206+
<CheckboxComponent
207+
className={cn("choice").elem("checkbox").mod({ notLeaf: !item.isLeaf }).toClassName()}
207208
checked={item.sel}
208209
indeterminate={!item.sel && item.indeterminate}
209210
disabled={item.isReadOnly()}
@@ -213,21 +214,25 @@ const HtxNewChoiceView = ({ item, store }) => {
213214
{item.html ? <span dangerouslySetInnerHTML={{ __html: sanitizeHtml(item.html) }} /> : item._value}
214215
{showHotkey && <Hint>[{item.hotkey}]</Hint>}
215216
</HintTooltip>
216-
</Elem>
217+
</CheckboxComponent>
217218
{!item.isLeaf ? (
218-
<Elem name="toggle" mod={{ collapsed }} component={Button} type="text" onClick={toogleCollapsed}>
219+
<Button
220+
className={cn("choice").elem("toggle").mod({ collapsed }).toClassName()}
221+
type="text"
222+
onClick={toogleCollapsed}
223+
>
219224
<IconChevron />
220-
</Elem>
225+
</Button>
221226
) : (
222227
false
223228
)}
224-
</Elem>
229+
</div>
225230
{item.nestedResults && item.children?.length ? (
226-
<Elem name="children" mod={{ collapsed }}>
231+
<div className={cn("choice").elem("children").mod({ collapsed }).toClassName()}>
227232
{Tree.renderChildren(item, item.annotation)}
228-
</Elem>
233+
</div>
229234
) : null}
230-
</Block>
235+
</div>
231236
);
232237
};
233238

0 commit comments

Comments
 (0)