-
Notifications
You must be signed in to change notification settings - Fork 68
Fix (design library): improve selecting of patterns #3602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import AdvancedToolbarControl from '../advanced-toolbar-control' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Button from '../button' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * External deprendencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| i18n, isPro, devMode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from 'stackable' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * WordPress deprendencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dashicon, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dropdown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ToggleControl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@wordpress/components' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { __ } from '@wordpress/i18n' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const PLAN_OPTIONS = [ { key: '', label: __( 'All', i18n ) }, { key: 'free', label: __( 'Free', i18n ) }, { key: 'premium', label: __( 'Premium', i18n ) } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const HeaderActions = props => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedTab, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSelectedTab, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selectedPlan, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSelectedPlan, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setDoReset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClose, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = props | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { /* DEV NOTE: hide for now */ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <AdvancedToolbarControl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="stk-design-library-tabs" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullwidth={ false } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| controls={ [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: 'patterns', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: __( 'Patterns', i18n ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: 'pages', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: __( 'Pages', i18n ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value={ selectedTab } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange={ setSelectedTab } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isToggleOnly={ true } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allowReset={ false } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="stk-design-library__header-settings"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { devMode && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ToggleControl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label="Dev Mode" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checked={ !! localStorage.getItem( 'stk__design_library__dev_mode' ) || false } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange={ value => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| localStorage.setItem( 'stk__design_library__dev_mode', value ? '1' : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setTimeout( () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document?.querySelector( '.ugb-insert-library-button__wrapper .ugb-insert-library-button' )?.click() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, 100 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClose() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kaeizen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __nextHasNoMarginBottom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize label and make localStorage access SSR-safe Use i18n for the label and avoid referencing localStorage at render time without a window check. Apply: - <ToggleControl
- label="Dev Mode"
- checked={ !! localStorage.getItem( 'stk__design_library__dev_mode' ) || false }
+ <ToggleControl
+ label={ __( 'Dev Mode', i18n ) }
+ checked={ !!( typeof window !== 'undefined' && window.localStorage?.getItem( 'stk__design_library__dev_mode' ) ) }
onChange={ value => {
- localStorage.setItem( 'stk__design_library__dev_mode', value ? '1' : '' )
+ try {
+ if ( typeof window !== 'undefined' ) {
+ window.localStorage?.setItem( 'stk__design_library__dev_mode', value ? '1' : '' )
+ }
+ } catch {}
setTimeout( () => {
document?.querySelector( '.ugb-insert-library-button__wrapper .ugb-insert-library-button' )?.click()
}, 100 )
- onClose()
+ onClose?.()
} }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon="image-rotate" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconSize={ 14 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={ __( 'Refresh Library', i18n ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="ugb-modal-design-library__refresh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={ () => setDoReset( true ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { ! isPro && <Dropdown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| focusOnMount="container" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderToggle={ ( { onToggle } ) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={ onToggle } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={ { height: 'auto' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon="arrow-down-alt2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconSize={ 12 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconPosition="right" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| variant="secondary" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Dashicon icon="lock" size={ 12 } /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span>{ selectedPlan.label }</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kaeizen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderContent={ ( { onClose } ) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="stk-design-library__plan-dropdown"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { PLAN_OPTIONS.map( ( plan, i ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={ i } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={ () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSelectedPlan( plan ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClose() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { plan.label } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.