Skip to content

Commit

Permalink
icon picker control first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
junaidbhura committed Apr 12, 2024
1 parent 63654cf commit f2554fb
Show file tree
Hide file tree
Showing 8 changed files with 6,597 additions and 14,993 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: '13.x'
node-version: '18.x'

- name: Checkout repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion assets/dist/blocks.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/dist/editor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions assets/src/components/icon-picker-control/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.gumponents-icon-picker-control {

&__modal {
width: 534px;
height: 500px;
max-height: 80%;
}

&__icons {
display: flex;
flex-wrap: wrap;
gap: 20px;
}

&__icon {
width: 50px;
height: 50px;
display: flex;
place-items: center;
border: 1px solid rgb(221, 221, 221);
border-radius: 8px;
cursor: pointer;

svg {
width: 100%;
height: 100%;
}
}
}
132 changes: 132 additions & 0 deletions assets/src/components/icon-picker-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import './editor.scss';

import wp from 'wp';

const { __ } = wp.i18n;
const {
Modal,
Button,
BaseControl,
Icon,
} = wp.components;
const {
useState,
} = wp.element;

function IconPickerControl( { value, help, modalTitle = __( 'Select Icon' ), label = __( 'Select icon' ), buttonLabel = __( 'Select icon' ), removeLabel = __( 'Remove icon' ) } ) {
const [ modalOpen, setModalOpen ] = useState( true );

/**
* Open modal.
*/
const openModal = () => {
setModalOpen( true );
};

return (
<>
<BaseControl
help={ help }
label={ label }
className="gumponents-icon-picker-control"
>
<Button
isSecondary
onClick={ openModal }
>
{ buttonLabel }
</Button>

{ value &&
<Button onClick={ null } isLink isDestructive>
{ removeLabel }
</Button>
}
</BaseControl>
{ modalOpen &&
<Modal
title={modalTitle}
className="gumponents-icon-picker-control__modal"
onRequestClose={() => setModalOpen(false)}
>
<div className="gumponents-icon-picker-control__icons">
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
<div className="gumponents-icon-picker-control__icon" role="button">
<Icon
icon={() => (
<svg>
<path d="M5 4v3h5.5v12h3V7H19V4z"/>
</svg>
)}
/>
</div>
</div>
<div className="gumponents-icon-picker-control__buttons">
<Button
isDefault
onClick={ () => setModalOpen( false ) }
>
Select
</Button>
</div>
</Modal>
}
</>
);
}

export default IconPickerControl;

2 changes: 2 additions & 0 deletions assets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import LinkControl from './components/link-control';
import GalleryControl from './components/gallery-control';
import ColorPaletteControl from './components/color-palette-control';
import RelationshipControl from './components/relationship-control';
import IconPickerControl from './components/icon-picker-control';

window.gumponents = {
// Components.
Expand All @@ -37,5 +38,6 @@ window.gumponents = {
GalleryControl,
ColorPaletteControl,
RelationshipControl,
IconPickerControl,
},
};
Loading

0 comments on commit f2554fb

Please sign in to comment.