diff --git a/.wordpress-org/screenshot-4.png b/.wordpress-org/screenshot-4.png new file mode 100644 index 0000000..a5a4d72 Binary files /dev/null and b/.wordpress-org/screenshot-4.png differ diff --git a/readme.txt b/readme.txt index 9d62d05..adb9403 100644 --- a/readme.txt +++ b/readme.txt @@ -215,9 +215,13 @@ Look under the "Styling" tab and turn on "Clamp Values", which will compute the 1. Choose from more than 25 themes. 2. Customize fonts, themes, and behavior. 3. Example showing light theme with padding disabled. +4. Example showing a header with a string using Palenight theme. == Changelog == +- Feature: Add additional header styles +- Feature: Allow overriding the label in the header + = 1.5.1 - 2022-09-08 = - Fix: Fix padding on copy button when padding is disabled diff --git a/src/block.json b/src/block.json index 2b73f17..a1df4d6 100644 --- a/src/block.json +++ b/src/block.json @@ -20,6 +20,7 @@ "lineNumbers": { "type": "boolean" }, "clampFonts": { "type": "boolean", "default": false }, "headerType": { "type": "string" }, + "headerString": { "type": "string" }, "disablePadding": { "type": "boolean", "default": false }, "startingLineNumber": { "type": "number", "default": 1 }, "frame": { "type": "boolean" }, diff --git a/src/editor/components/HeaderSelect.tsx b/src/editor/components/HeaderSelect.tsx index 36bfdf4..8b3cf54 100644 --- a/src/editor/components/HeaderSelect.tsx +++ b/src/editor/components/HeaderSelect.tsx @@ -1,7 +1,10 @@ import { BaseControl } from '@wordpress/components'; import { sprintf, __ } from '@wordpress/i18n'; import { Attributes } from '../../types'; -import { HeaderType } from './HeaderType'; +import { Headlights } from './headers/Headlights'; +import { HeadlightsMuted } from './headers/HeadlightsMuted'; +import { HeadlightsMutedAlt } from './headers/HeadlightsMutedAlt'; +import { SimpleString } from './headers/SimpleString'; type HeaderSelectProps = { attributes: Attributes; @@ -12,7 +15,16 @@ export const HeaderSelect = ({ attributes, onClick }: HeaderSelectProps) => { const types = { none: __('None', 'code-block-pro'), headlights: __('Headlights', 'code-block-pro'), + headlightsMuted: __('Headlights muted', 'code-block-pro'), + headlightsMutedAlt: __('Headlights muted alt', 'code-block-pro'), + simpleString: __('Simple string', 'code-block-pro'), }; + + const attributesWithoutHeaderType = { + ...attributes, + } as Partial; + delete attributesWithoutHeaderType.headerType; + return (
{Object.entries(types).map(([slug, type]) => ( @@ -33,7 +45,10 @@ export const HeaderSelect = ({ attributes, onClick }: HeaderSelectProps) => { 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-scroll"> - + {
); }; + +export const HeaderType = (attributes: Partial) => { + const { headerType } = attributes; + if (headerType === 'headlights') { + return ; + } + if (headerType === 'headlightsMuted') { + return ; + } + if (headerType === 'headlightsMutedAlt') { + return ; + } + if (headerType === 'simpleString') { + return ; + } + return null; +}; diff --git a/src/editor/components/HeaderType.tsx b/src/editor/components/HeaderType.tsx deleted file mode 100644 index 243e9f4..0000000 --- a/src/editor/components/HeaderType.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { HeadlightsIcon } from '../../icons'; -import { Attributes } from '../../types'; - -export const HeaderType = ({ headerType, bgColor }: Partial) => { - if (headerType === 'headlights') { - return ( - - - - ); - } - return null; -}; diff --git a/src/editor/components/headers/Headlights.tsx b/src/editor/components/headers/Headlights.tsx new file mode 100644 index 0000000..61f5b23 --- /dev/null +++ b/src/editor/components/headers/Headlights.tsx @@ -0,0 +1,43 @@ +import { Attributes } from '../../../types'; + +export const Headlights = ({ bgColor }: Partial) => ( + + + + + + + + + +); diff --git a/src/editor/components/headers/HeadlightsMuted.tsx b/src/editor/components/headers/HeadlightsMuted.tsx new file mode 100644 index 0000000..d8f5ed4 --- /dev/null +++ b/src/editor/components/headers/HeadlightsMuted.tsx @@ -0,0 +1,59 @@ +import { colord, AnyColor } from 'colord'; +import { Attributes } from '../../../types'; + +export const HeadlightsMuted = ({ + textColor, + bgColor, +}: Partial) => ( + + + + + + + + + +); diff --git a/src/editor/components/headers/HeadlightsMutedAlt.tsx b/src/editor/components/headers/HeadlightsMutedAlt.tsx new file mode 100644 index 0000000..3ee94f9 --- /dev/null +++ b/src/editor/components/headers/HeadlightsMutedAlt.tsx @@ -0,0 +1,49 @@ +import { colord, AnyColor } from 'colord'; +import { Attributes } from '../../../types'; + +export const HeadlightsMutedAlt = ({ bgColor }: Partial) => { + const bgC = colord(bgColor as AnyColor); + const bg = bgC.isDark() ? bgC.lighten(0.05) : bgC.darken(0.05); + return ( + + + + + + + + + + ); +}; diff --git a/src/editor/components/headers/SimpleString.tsx b/src/editor/components/headers/SimpleString.tsx new file mode 100644 index 0000000..4f7db49 --- /dev/null +++ b/src/editor/components/headers/SimpleString.tsx @@ -0,0 +1,31 @@ +import { colord, AnyColor } from 'colord'; +import { Lang } from 'shiki'; +import { Attributes } from '../../../types'; +import { languages } from '../../../util/languages'; + +export const SimpleString = ({ + language, + bgColor, + textColor, + headerString, +}: Partial) => { + const bgC = colord(bgColor as AnyColor); + const bg = bgC.isDark() ? bgC.lighten(0.05) : bgC.darken(0.05); + const textC = colord(textColor as AnyColor); + const text = textC.isDark() ? textC.lighten(0.05) : textC.darken(0.05); + return ( + + {headerString || languages[language as Lang]} + + ); +}; diff --git a/src/editor/controls/Sidebar.tsx b/src/editor/controls/Sidebar.tsx index 0cb7e60..83931d3 100644 --- a/src/editor/controls/Sidebar.tsx +++ b/src/editor/controls/Sidebar.tsx @@ -1,6 +1,7 @@ import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody, + TextControl, BaseControl, SelectControl, Button, @@ -32,6 +33,8 @@ export const SidebarControls = ({ const { updateThemeHistory } = useThemeStore(); const { setPreviousSettings } = useGlobalStore(); + const showHeaderTextEdit = ['simpleString'].includes(attributes.headerType); + return ( ) : null} + {showHeaderTextEdit && ( + + { + setAttributes({ headerString }); + }} + value={attributes.headerString ?? ''} + /> + + )} diff --git a/src/front/BlockOutput.tsx b/src/front/BlockOutput.tsx index ac78f62..2adf9ee 100644 --- a/src/front/BlockOutput.tsx +++ b/src/front/BlockOutput.tsx @@ -1,5 +1,5 @@ import { RichText, useBlockProps as blockProps } from '@wordpress/block-editor'; -import { HeaderType } from '../editor/components/HeaderType'; +import { HeaderType } from '../editor/components/HeaderSelect'; import { Attributes } from '../types'; import { fontFamilyLong, maybeClamp } from '../util/fonts'; import { CopyButton } from './CopyButton'; diff --git a/src/front/style.css b/src/front/style.css index 3855042..78ae288 100644 --- a/src/front/style.css +++ b/src/front/style.css @@ -35,14 +35,18 @@ .code-block-pro-copy-button { border: 0; background: none; - padding: 12px 12px 0 0; - @apply absolute top-0 right-0 left-auto bg-transparent border-none border-0 cursor-pointer opacity-30 focus:opacity-100 transition-opacity duration-200 ease-in-out leading-none z-10; + padding: 6px; + @apply absolute top-0 right-0 left-auto bg-transparent border-none border-0 cursor-pointer opacity-10 focus:opacity-40 transition-opacity duration-200 ease-in-out leading-none z-10; } .wp-block-kevinbatdorf-code-block-pro.padding-disabled .code-block-pro-copy-button { padding: 0; } .wp-block-kevinbatdorf-code-block-pro:hover .code-block-pro-copy-button { - @apply opacity-100; + @apply opacity-40; +} +/* .wp-block-kevinbatdorf-code-block-pro .code-block-pro-copy-button:active, */ +.wp-block-kevinbatdorf-code-block-pro .code-block-pro-copy-button:hover { + @apply opacity-90; } .code-block-pro-copy-button .without-check { @apply block; diff --git a/src/icons.tsx b/src/icons.tsx index 741af30..1fe1d49 100644 --- a/src/icons.tsx +++ b/src/icons.tsx @@ -30,34 +30,3 @@ export const languageIcon = () => ( /> ); -export const HeadlightsIcon = () => ( - - - - - - - -); diff --git a/src/index.tsx b/src/index.tsx index 2d70ca4..547514b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,7 +7,7 @@ import { Lang } from 'shiki'; import blockConfig from './block.json'; import { Edit } from './editor/Edit'; import { BlockFilter } from './editor/components/BlockFilter'; -import { HeaderType } from './editor/components/HeaderType'; +import { HeaderType } from './editor/components/HeaderSelect'; import { SidebarControls } from './editor/controls/Sidebar'; import { ToolbarControls } from './editor/controls/Toolbar'; import './editor/editor.css'; @@ -35,6 +35,7 @@ registerBlockType(blockConfig.name, { clampFonts: { type: 'boolean', default: false }, lineNumbers: { type: 'boolean' }, headerType: { type: 'string' }, + headerString: { type: 'string' }, disablePadding: { type: 'boolean', default: false }, startingLineNumber: { type: 'number', default: 1 }, frame: { type: 'boolean' }, diff --git a/src/types.ts b/src/types.ts index 2c82abc..4562f6a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,6 +14,7 @@ export type Attributes = { lineNumbers: boolean; clampFonts: boolean; headerType: string; + headerString?: string; disablePadding: boolean; startingLineNumber: number; frame: boolean; diff --git a/tsconfig.json b/tsconfig.json index b0bb6a4..8ecd973 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,11 +15,6 @@ "jsx": "preserve", "incremental": true }, - "include": [ - "src/**/*.ts", - "src/**/*.tsx", - "src/front/front.js", - "src/front/front.js" - ], + "include": ["src/**/*.ts", "src/**/*.tsx", "src/front/front.js"], "exclude": ["node_modules"] }