Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/static/js/options/options/ct-checkboxes.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + import {
2 + createElement,
3 + Component,
4 + createContext,
5 + Fragment,
6 + } from '@wordpress/element'
7 + import { maybeTransformUnorderedChoices } from '../helpers/parse-choices.js'
8 + import classnames from 'classnames'
9 +
10 + import _ from 'underscore'
11 +
12 + const Checkboxes = ({
13 + option,
14 + value,
15 + onChange,
16 + option: { view = 'checkboxes' },
17 + }) => {
18 + const orderedChoices = maybeTransformUnorderedChoices(option.choices)
19 +
20 + const { inline = false } = option
21 +
22 + if (view === 'checkboxes') {
23 + return (
24 + <div
25 + className="ct-option-checkbox"
26 + {...(inline ? { ['data-inline']: '' } : {})}
27 + {...(option.attr || {})}>
28 + {orderedChoices.map(({ key, value: choiceValue }) => (
29 + <label key={key}>
30 + <input
31 + type="checkbox"
32 + checked={
33 + typeof value[key] === 'boolean'
34 + ? value[key]
35 + : value[key] === 'true'
36 + }
37 + data-id={key}
38 + onChange={({ target: { checked } }) =>
39 + onChange({
40 + ...value,
41 + [key]: value[key]
42 + ? Object.values(value).filter((v) => v)
43 + .length === 1 &&
44 + !option.allow_empty
45 + ? true
46 + : false
47 + : true,
48 + })
49 + }
50 + />
51 +
52 + {choiceValue}
53 + </label>
54 + ))}
55 + </div>
56 + )
57 + }
58 +
59 + return (
60 + <ul
61 + className="ct-option-checkbox ct-buttons-group"
62 + {...(inline ? { ['data-inline']: '' } : {})}
63 + {...(option.attr || {})}>
64 + {orderedChoices.map(({ key, value: choiceValue }) => (
65 + <li
66 + className={classnames({
67 + active:
68 + typeof value[key] === 'boolean'
69 + ? value[key]
70 + : value[key] === 'true',
71 + })}
72 + data-id={key}
73 + key={key}
74 + onClick={({ target: { checked } }) =>
75 + onChange({
76 + ...value,
77 + [key]: value[key]
78 + ? Object.values(value).filter((v) => v)
79 + .length === 1 && !option.allow_empty
80 + ? true
81 + : false
82 + : true,
83 + })
84 + }>
85 + {choiceValue}
86 + </li>
87 + ))}
88 + </ul>
89 + )
90 + }
91 +
92 + export default Checkboxes
93 +