Skip to content

Commit

Permalink
refactor(hdom-components): dedupe toggle() internals
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 24, 2021
1 parent 936a9d7 commit 4b09d0e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/hdom-components/src/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ export const slideToggleDot = (opts: Partial<ToggleDotOpts> = {}) => {
...(vertical ? { cy: width + margin - br } : { cx }),
..._opts.fgOff,
};
return (_: any, attribs: any, state: boolean) => [
"svg",
{ ...svgSize, ...attribs },
["rect", state ? bgOn : bgOff],
["circle", state ? shapeOn : shapeOff],
];
return $toggle("circle", svgSize, bgOn, bgOff, shapeOn, shapeOff);
};

export const slideToggleRect = (opts: Partial<ToggleRectOpts> = {}) => {
Expand Down Expand Up @@ -111,10 +106,22 @@ export const slideToggleRect = (opts: Partial<ToggleRectOpts> = {}) => {
...(vertical ? { y: height + margin - pad - h } : { x: pm }),
..._opts.fgOff,
};
return (_: any, attribs: any, state: boolean) => [
"svg",
{ ...svgSize, ...attribs },
["rect", state ? bgOn : bgOff],
["rect", state ? shapeOn : shapeOff],
];
return $toggle("rect", svgSize, bgOn, bgOff, shapeOn, shapeOff);
};

const $toggle =
(
shape: string,
size: any,
bgOn: any,
bgOff: any,
shapeOn: any,
shapeOff: any
) =>
(_: any, attribs: any, state: boolean) =>
[
"svg",
{ ...size, ...attribs },
["rect", state ? bgOn : bgOff],
[shape, state ? shapeOn : shapeOff],
];

0 comments on commit 4b09d0e

Please sign in to comment.