| 1 |
import { InspectorControls } from '@wordpress/block-editor'; |
| 2 |
import { |
| 3 |
PanelBody, |
| 4 |
BaseControl, |
| 5 |
SelectControl, |
| 6 |
CheckboxControl, |
| 7 |
} from '@wordpress/components'; |
| 8 |
import { __ } from '@wordpress/i18n'; |
| 9 |
import { Theme } from 'shiki'; |
| 10 |
import { useLanguage } from '../../hooks/useLanguage'; |
| 11 |
import { useGlobalStore } from '../../state/global'; |
| 12 |
import { useThemeStore } from '../../state/theme'; |
| 13 |
import { AttributesPropsAndSetter } from '../../types'; |
| 14 |
import { languages } from '../../util/languages'; |
| 15 |
import { FontSizeSelect, FontLineHeightSelect } from '../components/FontSelect'; |
| 16 |
import { Notice } from '../components/Notice'; |
| 17 |
import { ThemeSelect } from '../components/ThemeSelect'; |
| 18 |
|
| 19 |
export const SidebarControls = ({ |
| 20 |
attributes, |
| 21 |
setAttributes, |
| 22 |
}: AttributesPropsAndSetter) => { |
| 23 |
const [language, setLanguage] = useLanguage({ attributes, setAttributes }); |
| 24 |
const { updateThemeHistory } = useThemeStore(); |
| 25 |
const { setPreviousSettings } = useGlobalStore(); |
| 26 |
|
| 27 |
return ( |
| 28 |
<InspectorControls> |
| 29 |
<PanelBody |
| 30 |
title={__('Settings', 'code-block-pro')} |
| 31 |
initialOpen={true}> |
| 32 |
<div className="code-block-pro-editor"> |
| 33 |
<BaseControl id="code-block-pro-language"> |
| 34 |
<SelectControl |
| 35 |
id="code-block-pro-language" |
| 36 |
label={__('Code Language', 'code-block-pro')} |
| 37 |
data-cy-cbp="language-select" |
| 38 |
value={language} |
| 39 |
onChange={setLanguage} |
| 40 |
options={Object.entries(languages).map( |
| 41 |
([value, label]) => ({ |
| 42 |
label, |
| 43 |
value, |
| 44 |
}), |
| 45 |
)} |
| 46 |
/> |
| 47 |
</BaseControl> |
| 48 |
<Notice /> |
| 49 |
</div> |
| 50 |
</PanelBody> |
| 51 |
<PanelBody |
| 52 |
title={__('Styling', 'code-block-pro')} |
| 53 |
initialOpen={false}> |
| 54 |
<div className="code-block-pro-editor"> |
| 55 |
<h2 className="m-0">{__('Font Size', 'code-block-pro')}</h2> |
| 56 |
<FontSizeSelect |
| 57 |
value={attributes.fontSize} |
| 58 |
onChange={(fontSize) => { |
| 59 |
setAttributes({ fontSize }); |
| 60 |
updateThemeHistory({ ...attributes, fontSize }); |
| 61 |
}} |
| 62 |
/> |
| 63 |
<h2 className="m-0"> |
| 64 |
{__('Line Height', 'code-block-pro')} |
| 65 |
</h2> |
| 66 |
<FontLineHeightSelect |
| 67 |
value={attributes.lineHeight} |
| 68 |
onChange={(lineHeight) => { |
| 69 |
setAttributes({ lineHeight }); |
| 70 |
updateThemeHistory({ |
| 71 |
...attributes, |
| 72 |
lineHeight, |
| 73 |
}); |
| 74 |
}} |
| 75 |
/> |
| 76 |
</div> |
| 77 |
</PanelBody> |
| 78 |
<PanelBody |
| 79 |
title={__('Themes', 'code-block-pro')} |
| 80 |
initialOpen={false}> |
| 81 |
<ThemeSelect |
| 82 |
{...attributes} |
| 83 |
onClick={(slug: Theme) => { |
| 84 |
setAttributes({ theme: slug }); |
| 85 |
updateThemeHistory({ ...attributes, theme: slug }); |
| 86 |
}} |
| 87 |
/> |
| 88 |
</PanelBody> |
| 89 |
<PanelBody |
| 90 |
title={__('Extra Settings', 'code-block-pro')} |
| 91 |
initialOpen={false}> |
| 92 |
<CheckboxControl |
| 93 |
label={__('Copy Button', 'code-block-pro')} |
| 94 |
help={__( |
| 95 |
'If checked, users will be able to copy your code snippet to their clipboard.', |
| 96 |
'code-block-pro', |
| 97 |
)} |
| 98 |
checked={attributes.copyButton} |
| 99 |
onChange={(value) => { |
| 100 |
setPreviousSettings({ copyButton: value }); |
| 101 |
setAttributes({ copyButton: value }); |
| 102 |
}} |
| 103 |
/> |
| 104 |
</PanelBody> |
| 105 |
</InspectorControls> |
| 106 |
); |
| 107 |
}; |
| 108 |
|