generated from KevinBatdorf/gutenberg-rust-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from KevinBatdorf/add-footer-support
Add footer support
- Loading branch information
Showing
15 changed files
with
276 additions
and
14 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
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,66 @@ | ||
import { BaseControl } from '@wordpress/components'; | ||
import { sprintf, __ } from '@wordpress/i18n'; | ||
import { Attributes } from '../../types'; | ||
import { SimpleStringEnd } from './footers/SimpleStringEnd'; | ||
|
||
type FooterSelectProps = { | ||
attributes: Attributes; | ||
onClick: (slug: string) => void; | ||
}; | ||
export const FooterSelect = ({ attributes, onClick }: FooterSelectProps) => { | ||
const { footerType, ...attributesWithoutFooterType }: Partial<Attributes> = | ||
attributes; | ||
const { bgColor } = attributes; | ||
const types = { | ||
none: __('None', 'code-block-pro'), | ||
simpleStringEnd: __('Simple string end', 'code-block-pro'), | ||
}; | ||
|
||
return ( | ||
<div className="code-block-pro-editor"> | ||
{Object.entries(types).map(([slug, type]) => ( | ||
<BaseControl | ||
id={`code-block-pro-footer-${slug}`} | ||
label={ | ||
footerType === slug | ||
? sprintf( | ||
__('%s (current)', 'code-block-pro'), | ||
type, | ||
) | ||
: type | ||
} | ||
help={ | ||
['simpleStringEnd'].includes(slug) | ||
? __('Update text in Settings', 'code-block-pro') | ||
: undefined | ||
} | ||
key={slug}> | ||
<button | ||
id={`code-block-pro-footer-${slug}`} | ||
type="button" | ||
onClick={() => onClick(slug)} | ||
className="p-0 border flex items-start w-full text-left outline-none cursor-pointer no-underline ring-offset-2 ring-offset-white focus:shadow-none focus:ring-wp overflow-x-auto"> | ||
<span className="pointer-events-none w-full"> | ||
<span | ||
className="block w-full h-8" | ||
style={{ backgroundColor: bgColor }} | ||
/> | ||
<FooterType | ||
footerType={slug} | ||
{...attributesWithoutFooterType} | ||
/> | ||
</span> | ||
</button> | ||
</BaseControl> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export const FooterType = (attributes: Partial<Attributes>) => { | ||
const { footerType } = attributes; | ||
if (footerType === 'simpleStringEnd') { | ||
return <SimpleStringEnd {...attributes} />; | ||
} | ||
return null; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { colord, AnyColor } from 'colord'; | ||
import { Lang } from 'shiki'; | ||
import { Attributes } from '../../../types'; | ||
import { languages } from '../../../util/languages'; | ||
|
||
export const SimpleStringEnd = ({ | ||
language, | ||
bgColor, | ||
textColor, | ||
footerString, | ||
footerLink, | ||
footerLinkTarget, | ||
disablePadding, | ||
}: Partial<Attributes>) => { | ||
const bgC = colord(bgColor as AnyColor); | ||
const textC = colord(textColor as AnyColor); | ||
const text = textC.isDark() ? textC.lighten(0.05) : textC.darken(0.05); | ||
return ( | ||
<span | ||
style={{ | ||
display: 'flex', | ||
alignItems: 'flex-end', | ||
padding: disablePadding ? '10px 0 0 0' : '10px', | ||
width: '100%', | ||
justifyContent: 'flex-end', | ||
backgroundColor: bgC.toHex(), | ||
color: text.toHex(), | ||
fontSize: '12px', | ||
lineHeight: '1', | ||
position: 'relative', | ||
}}> | ||
<Inner | ||
text={footerString || languages[language as Lang]} | ||
color={text.toHex()} | ||
link={footerLink} | ||
linkTarget={footerLinkTarget} | ||
/> | ||
</span> | ||
); | ||
}; | ||
|
||
const Inner = ({ | ||
text, | ||
color, | ||
link, | ||
linkTarget, | ||
}: { | ||
text?: string; | ||
color: string; | ||
link?: string; | ||
linkTarget?: boolean; | ||
}) => { | ||
if (!link) return <>{text}</>; | ||
const style = { | ||
color, | ||
// attempt to reset the link to not inheret from theme | ||
textDecoration: 'none', | ||
fontWeight: 'normal', | ||
border: 'none', | ||
background: 'none', | ||
borderRadius: '0', | ||
padding: '0', | ||
margin: '0', | ||
}; | ||
if (linkTarget) { | ||
return ( | ||
<a | ||
className="cbp-footer-link" | ||
href={link} | ||
style={style} | ||
target={'_blank'} | ||
// Gutenberg required | ||
rel={'noopener noreferrer'}> | ||
{text} | ||
</a> | ||
); | ||
} | ||
return ( | ||
<a className="cbp-footer-link" href={link} style={style}> | ||
{text} | ||
</a> | ||
); | ||
}; |
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
Oops, something went wrong.