-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assembler: Add interaction in the Pages screen (#83501)
- Loading branch information
1 parent
68e925b
commit 755b993
Showing
8 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../stepper/declarative-flow/internals/steps-repository/pattern-assembler/hooks/use-pages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
const usePages = () => { | ||
const [ searchParams, setSearchParams ] = useSearchParams(); | ||
const page_slugs = ( searchParams.get( 'page_slugs' ) || '' ).split( ',' ).filter( Boolean ); | ||
|
||
const pages = page_slugs || []; | ||
|
||
const setPages = ( pages: string[] ) => { | ||
setSearchParams( | ||
( currentSearchParams ) => { | ||
if ( pages.length === 0 ) { | ||
currentSearchParams.delete( 'page_slugs' ); | ||
} else { | ||
currentSearchParams.set( 'page_slugs', pages.join( ',' ) ); | ||
} | ||
|
||
return currentSearchParams; | ||
}, | ||
{ replace: true } | ||
); | ||
}; | ||
|
||
return { pages, setPages }; | ||
}; | ||
|
||
export default usePages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ding/stepper/declarative-flow/internals/steps-repository/pattern-assembler/page-list.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.page-list { | ||
button { | ||
border-radius: 2px; | ||
|
||
&:focus-visible:not(:disabled) { | ||
border-color: var(--color-primary-light); | ||
box-shadow: 0 0 0 2px var(--color-primary-light); | ||
} | ||
} | ||
} | ||
|
||
.page-list-item { | ||
cursor: pointer; | ||
padding: 10px 8px; | ||
transition: background-color 0.2s; | ||
|
||
&:hover { | ||
&__label { | ||
color: var(--studio-blue-50); | ||
} | ||
} | ||
|
||
|
||
&--selected &__icon { | ||
background-color: var(--studio-blue-50); | ||
border-color: var(--studio-blue-50); | ||
} | ||
|
||
&--disabled { | ||
cursor: default; | ||
} | ||
|
||
&--disabled &__icon { | ||
background-color: var(--studio-gray-20); | ||
} | ||
|
||
&--disabled &__label { | ||
color: var(--studio-gray-100); | ||
} | ||
|
||
&__icon { | ||
align-items: center; | ||
border-radius: 16px; /* stylelint-disable-line scales/radii */ | ||
border: 1px solid var(--studio-gray-20); | ||
box-sizing: border-box; | ||
color: #fff; | ||
display: flex; | ||
height: 16px; | ||
justify-content: center; | ||
width: 16px; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
&__label { | ||
color: var(--studio-gray-100); | ||
text-transform: capitalize; | ||
} | ||
} | ||
|
78 changes: 78 additions & 0 deletions
78
...nding/stepper/declarative-flow/internals/steps-repository/pattern-assembler/page-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Gridicon } from '@automattic/components'; | ||
import { | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
__unstableComposite as Composite, | ||
__unstableUseCompositeState as useCompositeState, | ||
__unstableCompositeItem as CompositeItem, | ||
FlexItem, | ||
} from '@wordpress/components'; | ||
import classnames from 'classnames'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { ORDERED_PAGES } from './constants'; | ||
import './page-list.scss'; | ||
|
||
interface PageListItemProps { | ||
label: string; | ||
isSelected?: boolean; | ||
isDisabled?: boolean; | ||
} | ||
|
||
const PageListItem = ( { label, isSelected, isDisabled }: PageListItemProps ) => { | ||
return ( | ||
<HStack | ||
className={ classnames( 'page-list-item', { | ||
'page-list-item--selected': isSelected, | ||
'page-list-item--disabled': isDisabled, | ||
} ) } | ||
justify="flex-start" | ||
spacing={ 3 } | ||
> | ||
<FlexItem className="page-list-item__icon" display="flex"> | ||
{ /* eslint-disable wpcalypso/jsx-gridicon-size */ } | ||
<Gridicon icon="checkmark" size={ 10 } /> | ||
</FlexItem> | ||
<FlexItem className="page-list-item__label">{ label }</FlexItem> | ||
</HStack> | ||
); | ||
}; | ||
|
||
interface PageListProps { | ||
selectedPages: string[]; | ||
onSelectPage: ( selectedPage: string ) => void; | ||
} | ||
|
||
const PageList = ( { selectedPages, onSelectPage }: PageListProps ) => { | ||
const translate = useTranslate(); | ||
const composite = useCompositeState( { orientation: 'vertical' } ); | ||
|
||
return ( | ||
<Composite | ||
{ ...composite } | ||
role="listbox" | ||
className="page-list" | ||
aria-label={ translate( 'Pages' ) } | ||
> | ||
<VStack spacing={ 0 }> | ||
<CompositeItem { ...composite } role="option" as="button" disabled> | ||
<PageListItem label={ translate( 'Homepage' ) } isDisabled /> | ||
</CompositeItem> | ||
{ ORDERED_PAGES.map( ( page ) => { | ||
return ( | ||
<CompositeItem | ||
key={ page } | ||
role="option" | ||
as="button" | ||
{ ...composite } | ||
onClick={ () => onSelectPage( page ) } | ||
> | ||
<PageListItem label={ page } isSelected={ selectedPages.includes( page ) } /> | ||
</CompositeItem> | ||
); | ||
} ) } | ||
</VStack> | ||
</Composite> | ||
); | ||
}; | ||
|
||
export default PageList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters