Skip to content

Commit

Permalink
Refactor popovers with wordpress components (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano authored Oct 20, 2024
1 parent 10797c2 commit db3d761
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 58 deletions.
35 changes: 17 additions & 18 deletions src/controls/border-color-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Button,
Popover,
ColorPalette,
__experimentalSpacer as Spacer,
__experimentalText as Text,
} from '@wordpress/components';
import { store as blockEditorStore } from '@wordpress/block-editor';
Expand Down Expand Up @@ -140,15 +141,14 @@ export default function BorderColorControl( {
isMixed={ isMixed }
/>
{ isPickerOpen && ! pickerIndex && (
<Popover
className="ftb-border-color-control__popover"
onClose={ handleOnPickerClose }
>
<ColorPalette
colors={ colors }
value={ allInputValue || '' }
onChange={ handleOnChangeAll }
/>
<Popover onClose={ handleOnPickerClose }>
<Spacer padding={ 4 } marginBottom={ 0 }>
<ColorPalette
colors={ colors }
value={ allInputValue || '' }
onChange={ handleOnChangeAll }
/>
</Spacer>
</Popover>
) }
</div>
Expand All @@ -165,15 +165,14 @@ export default function BorderColorControl( {
isTransparent={ values[ item.value ] === 'transparent' }
/>
{ isPickerOpen && pickerIndex === index && (
<Popover
className="ftb-border-color-control__popover"
onClose={ handleOnPickerClose }
>
<ColorPalette
colors={ colors }
value={ values[ item.value ] || '' }
onChange={ ( value ) => handleOnChange( value, item.value ) }
/>
<Popover onClose={ handleOnPickerClose }>
<Spacer padding={ 4 } marginBottom={ 0 }>
<ColorPalette
colors={ colors }
value={ values[ item.value ] || '' }
onChange={ ( value ) => handleOnChange( value, item.value ) }
/>
</Spacer>
</Popover>
) }
</div>
Expand Down
15 changes: 9 additions & 6 deletions src/controls/color-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Popover,
ColorPalette,
SlotFillProvider,
__experimentalSpacer as Spacer,
__experimentalText as Text,
} from '@wordpress/components';
import { store as blockEditorStore } from '@wordpress/block-editor';
Expand Down Expand Up @@ -84,12 +85,14 @@ export default function ColorControl( {
isTransparent={ value === 'transparent' }
/>
{ isPickerOpen && (
<Popover className="ftb-color-control__popover" onClose={ handleOnPickerClose }>
<ColorPalette
colors={ [ ...colors, ...colorsProp ] }
value={ value || '' }
onChange={ handleOnChange }
/>
<Popover onClose={ handleOnPickerClose }>
<Spacer padding={ 4 } marginBottom={ 0 }>
<ColorPalette
colors={ [ ...colors, ...colorsProp ] }
value={ value || '' }
onChange={ handleOnChange }
/>
</Spacer>
</Popover>
) }
</div>
Expand Down
9 changes: 0 additions & 9 deletions src/controls/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,3 @@
padding-top: 8px;
}
}

// Popover styles.
.ftb-border-color-control__popover,
.ftb-color-control__popover {

.components-popover__content {
padding: 16px;
}
}
34 changes: 21 additions & 13 deletions src/settings/global-settings/setting-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
Spinner,
RangeControl,
ToggleControl,
__experimentalText as Text,
__experimentalSpacer as Spacer,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalUnitControl as UnitControl,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalToggleGroupControl as ToggleGroupControl,
Expand Down Expand Up @@ -754,19 +758,23 @@ export default function SettingModal( { options, isAdministrator, setIsSettingMo
focusOnMount="firstElement"
onClose={ () => setIsResetPopup( false ) }
>
<p>{ __( 'Are you sure?', 'flexible-table-block' ) }</p>
<div className="ftb-global-setting-modal__confirm-popover-buttons">
<Button isDestructive onClick={ handleResetOptions } size="compact">
{ __( 'Restore', 'flexible-table-block' ) }
</Button>
<Button
variant="secondary"
onClick={ () => setIsResetPopup( false ) }
size="compact"
>
{ __( 'Cancel', 'flexible-table-block' ) }
</Button>
</div>
<Spacer marginBottom={ 0 } padding={ 2 }>
<VStack spacing={ 4 }>
<Text as="p">{ __( 'Are you sure?', 'flexible-table-block' ) }</Text>
<HStack>
<Button isDestructive onClick={ handleResetOptions } size="compact">
{ __( 'Restore', 'flexible-table-block' ) }
</Button>
<Button
variant="secondary"
onClick={ () => setIsResetPopup( false ) }
size="compact"
>
{ __( 'Cancel', 'flexible-table-block' ) }
</Button>
</HStack>
</VStack>
</Spacer>
</Popover>
) }
</Button>
Expand Down
12 changes: 0 additions & 12 deletions src/settings/global-settings/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,6 @@

.ftb-global-setting-modal__confirm-popover .components-popover__content {
min-width: 150px;
padding: 8px;

p {
margin: 0 0 1em;
}
}

.ftb-global-setting-modal__confirm-popover-buttons {
display: flex;
gap: 8px;
justify-content: space-between;
white-space: nowrap;
}

.ftb-global-setting-modal__notice {
Expand Down

0 comments on commit db3d761

Please sign in to comment.