deprecations
2 years ago
condition.group.item.js
2 years ago
conditional.model.context.js
2 years ago
conditions.is.empty.js
2 years ago
conditions.list.js
2 years ago
conditions.modal.content.js
2 years ago
conditions.modal.js
2 years ago
edit.js
2 years ago
index.js
2 years ago
options.js
2 years ago
preview.js
2 years ago
save.js
2 years ago
condition.group.item.js
81 lines
| 1 | import ConditionalModalContext from './conditional.model.context'; |
| 2 | |
| 3 | const { |
| 4 | DetailsContainer, |
| 5 | HoverContainer, |
| 6 | HumanReadableConditions, |
| 7 | } = JetFBComponents; |
| 8 | const { |
| 9 | useBlockAttributes, |
| 10 | } = JetFBHooks; |
| 11 | |
| 12 | const { |
| 13 | useState, |
| 14 | useEffect, |
| 15 | useContext, |
| 16 | } = wp.element; |
| 17 | |
| 18 | const { |
| 19 | __, |
| 20 | } = wp.i18n; |
| 21 | const { |
| 22 | Button, |
| 23 | } = wp.components; |
| 24 | |
| 25 | function ConditionGroupItem( { group } ) { |
| 26 | const [ isHover, setHover ] = useState( false ); |
| 27 | const { setShowModal } = useContext( ConditionalModalContext ); |
| 28 | const [ attributes, setAttributes ] = useBlockAttributes(); |
| 29 | |
| 30 | const conditions = group.map( ( { condition } ) => condition ); |
| 31 | const indexes = group.map( ( { index } ) => index ); |
| 32 | |
| 33 | return <div |
| 34 | className="jet-fb p-relative" |
| 35 | onMouseOver={ () => setHover( true ) } |
| 36 | onMouseOut={ () => setHover( false ) } |
| 37 | > |
| 38 | <HoverContainer isHover={ isHover }> |
| 39 | <Button |
| 40 | isSmall |
| 41 | isSecondary |
| 42 | icon={ 'edit' } |
| 43 | onClick={ () => { |
| 44 | setAttributes( |
| 45 | ( { conditions } ) => conditions.map( |
| 46 | ( current, index ) => { |
| 47 | current.__visible = index === indexes[ 0 ]; |
| 48 | return current; |
| 49 | }, |
| 50 | ), |
| 51 | ); |
| 52 | setShowModal( prev => !prev ); |
| 53 | } } |
| 54 | > |
| 55 | { __( 'Edit', 'jet-form-builder' ) } |
| 56 | </Button> |
| 57 | <Button |
| 58 | isSmall |
| 59 | isDestructive |
| 60 | icon={ 'trash' } |
| 61 | onClick={ () => { |
| 62 | setAttributes( { |
| 63 | conditions: attributes.conditions.filter( |
| 64 | ( current, index ) => !indexes.includes( index ), |
| 65 | ), |
| 66 | } ); |
| 67 | } } |
| 68 | > |
| 69 | { __( 'Delete', 'jet-form-builder' ) } |
| 70 | </Button> |
| 71 | </HoverContainer> |
| 72 | <DetailsContainer> |
| 73 | <HumanReadableConditions |
| 74 | conditions={ conditions } |
| 75 | showWarning |
| 76 | /> |
| 77 | </DetailsContainer> |
| 78 | </div>; |
| 79 | } |
| 80 | |
| 81 | export default ConditionGroupItem; |