diff --git a/assets/sass/theme.scss b/assets/sass/theme.scss index 054a6bf..eed51d8 100644 --- a/assets/sass/theme.scss +++ b/assets/sass/theme.scss @@ -71,7 +71,8 @@ $wp--custom--button--border-radius: --wp--custom--button--border-radius; $wp--custom--button--hover--bg: --wp--custom--button--hover--bg; $wp--custom--button--hover--text: --wp--custom--button--hover--text; $wp--custom--button--hover--border-color: --wp--custom--button--hover--border-color; -$wp--custom--button--padding: --wp--custom--button--padding; +$wp--custom--button--padding--h: --wp--custom--button--padding--h; +$wp--custom--button--padding--v: --wp--custom--button--padding--v; $wp--custom--form--border--color: --wp--custom--form--border--color; $wp--custom--form--border--width: --wp--custom--form--border--width; $wp--custom--form--input--color: --wp--custom--form--input--color; diff --git a/src/JsonData.php b/src/JsonData.php index f2ee922..8f402f1 100644 --- a/src/JsonData.php +++ b/src/JsonData.php @@ -4,6 +4,8 @@ namespace ItalyStrap\ExperimentalTheme; +use ItalyStrap\Config\Config; +use ItalyStrap\Config\ConfigInterface; use ItalyStrap\ThemeJsonGenerator\Domain\SectionNames; use ItalyStrap\ThemeJsonGenerator\Domain\Settings\Collection; use ItalyStrap\ThemeJsonGenerator\Domain\Settings\CollectionInterface; @@ -94,7 +96,8 @@ final class JsonData public const BUTTON_HOVER_BG = Custom::CATEGORY . '.button.hover.bg'; public const BUTTON_HOVER_TEXT = Custom::CATEGORY . '.button.hover.text'; public const BUTTON_HOVER_BORDER_COLOR = Custom::CATEGORY . '.button.hover.borderColor'; - public const BUTTON_PADDING = Custom::CATEGORY . '.button.padding'; + public const BUTTON_PADDING_V = Custom::CATEGORY . '.button.padding.v'; + public const BUTTON_PADDING_H = Custom::CATEGORY . '.button.padding.h'; public const FORM_BORDER_COLOR = Custom::CATEGORY . '.form.borderColor'; public const FORM_BORDER_WIDTH = Custom::CATEGORY . '.form.borderWidth'; public const FORM_INPUT_COLOR = Custom::CATEGORY . '.form.input.color'; @@ -240,7 +243,7 @@ private function registerDuotone(CollectionInterface $collection): void private function registerFontSizes(CollectionInterface $collection): void { $collection - ->add(new FontSize('base', 'Base font size 16px', 'clamp(1.125rem, 2vw, 1.5rem)')) + ->add(new FontSize('base', 'Base font size 16px', 'clamp(1rem, 2vw, 1.5rem)')) ->add(new FontSize('h1', 'Used in H1 titles', 'calc( {{fontSize.base}} * 2.8125)')) ->add(new FontSize('h2', 'Used in H2 titles', 'calc( {{fontSize.base}} * 2.1875)')) ->add(new FontSize('h3', 'Used in H3 titles', 'calc( {{fontSize.base}} * 1.625)')) @@ -316,13 +319,21 @@ private function registerCustom(CollectionInterface $collection): void 'bg' => $collection->get(self::COLOR_BASE), 'text' => $collection->get(self::COLOR_BUTTON_TEXT_HOVER), 'borderColor' => 'transparent', - 'borderRadius' => 'calc( {{fontSize.base}} /4)', +// 'borderRadius' => 'calc( {{fontSize.base}} /4)', + 'borderRadius' => (string)(new CalcExperimental( + $collection->get(self::FONT_SIZE_BASE)->var(), + '/', + '3' + )), 'hover' => [ 'bg' => $collection->get(self::COLOR_BUTTON_BG_HOVER), 'text' => $collection->get(self::COLOR_BUTTON_TEXT_HOVER), 'borderColor' => 'transparent', ], - 'padding' => ' 0.25em 0.7em', + 'padding' => [ + 'h' => '0.75em', + 'v' => '0.375em', + ], ], 'form' => [ 'border' => [ @@ -340,14 +351,8 @@ private function registerCustom(CollectionInterface $collection): void ], 'query' => [ 'post' => [ -// 'title' => 'var:preset|fontSize|h1', ], ], - // 'site-blocks' => [ - // 'margin' => [ - // 'top' => '', - // ], - // ], ]); $collection->addMultiple( @@ -374,22 +379,17 @@ public function buildJsonData(CollectionInterface $collection): array $this->registerFontFamily($collection); $this->registerCustom($collection); - return [ + $jsonData = new Config([ SectionNames::SCHEMA => 'https://schemas.wp.org/trunk/theme.json', SectionNames::VERSION => 1, SectionNames::SETTINGS => [ 'color' => [ 'custom' => true, 'link' => true, - 'palette' => $collection->toArrayByCategory(Palette::CATEGORY), - 'gradients' => $collection->toArrayByCategory(Gradient::CATEGORY), - 'duotone' => $collection->toArrayByCategory(Duotone::CATEGORY), ], 'typography' => [ 'customFontSize' => true, 'customLineHeight' => true, - 'fontSizes' => $collection->toArrayByCategory(FontSize::CATEGORY), - 'fontFamilies' => $collection->toArrayByCategory(FontFamily::CATEGORY), ], 'spacing' => [ 'blockGap' => true, @@ -403,18 +403,10 @@ public function buildJsonData(CollectionInterface $collection): array 'customStyle' => true, 'customWidth' => true, ], - 'custom' => $collection->toArrayByCategory(Custom::CATEGORY), "blocks" => [ "core/button" => [ "color" => [ 'custom' => false, -// 'palette' => [ -// [ -// "slug" => "primary", -// "color" => "#044c75", -// "name" => "Primary" -// ] -// ], ], ], "core/navigation" => [ @@ -454,7 +446,7 @@ public function buildJsonData(CollectionInterface $collection): array ->fontFamily(self::FONT_FAMILY_BASE) ->fontSize(self::FONT_SIZE_BASE) ->fontStyle('normal') - ->fontWeight('300') + ->fontWeight('400') ->letterSpacing('normal') ->lineHeight(self::LINE_HEIGHT_M) ->textDecoration('none') @@ -475,6 +467,72 @@ public function buildJsonData(CollectionInterface $collection): array * ============================================ */ 'elements' => [ + /** + * .wp-element-button + * + * BC = .wp-block-button__link + */ + 'button' => [ + 'border' => (new Border($collection)) + ->color(self::BUTTON_BORDER_COLOR) + ->radius(self::BUTTON_BORDER_RADIUS) + ->style('solid') + ->width('1px') + ->toArray(), + 'color' => (new Color($collection)) + ->background(self::BUTTON_BG) + ->text(self::BUTTON_TEXT) + ->toArray(), + 'spacing' => [ + 'padding' => (new Spacing($collection)) + ->vertical(self::BUTTON_PADDING_V) + ->horizontal(self::BUTTON_PADDING_H) + ->toArray(), + ], + 'typography' => (new Typography($collection)) + ->fontFamily(self::FONT_FAMILY_BASE) + ->fontSize(self::FONT_SIZE_BASE) + ->textDecoration('none') + ->lineHeight(self::LINE_HEIGHT_S) + ->toArray(), + ':hover' => [ + 'color' => (new Color($collection)) + ->background(self::BUTTON_HOVER_BG) + ->text(self::BUTTON_HOVER_TEXT) + ->toArray(), + 'border' => [ + 'color' => (new Color($collection)) + ->text(self::BUTTON_HOVER_BORDER_COLOR) + ->toArray() + ], + ], + ':focus' => [ + 'color' => (new Color($collection)) + ->background(self::BUTTON_HOVER_BG) + ->toArray(), + 'border' => [ + 'color' => (new Color($collection)) + ->text(self::BUTTON_HOVER_BORDER_COLOR) + ->toArray(), + ], + 'outline' => [ + 'color' => $collection->get(self::COLOR_GRAY_300)->var(), + 'offset' => '1px', + 'style' => 'dotted', + 'width' => '1px', + ], + ], + ':active' => [ + 'color' => (new Color($collection)) + ->background(self::BUTTON_HOVER_BG) + ->toArray(), + 'border' => [ + 'color' => (new Color($collection)) + ->text(self::BUTTON_HOVER_BORDER_COLOR) + ->toArray(), + ], + ], + ], 'link' => [ 'color' => (new Color($collection)) ->text(self::COLOR_LINK_TEXT) @@ -534,6 +592,32 @@ public function buildJsonData(CollectionInterface $collection): array * ============================================ */ 'blocks' => [ + /** + * .wp-element-button + * .wp-block-button__link + */ + 'core/button' => [ + 'variations' => [ + 'outline' => [ + 'border' => (new Border($collection)) + ->color(self::COLOR_BASE) + ->radius(self::BUTTON_BORDER_RADIUS) + ->style('solid') + ->width('1px') + ->toArray(), + 'color' => (new Color($collection)) + ->background(self::COLOR_BODY_BG) + ->text(self::COLOR_BASE) + ->toArray(), + 'spacing' => [ + 'padding' => (new Spacing($collection)) + ->vertical(self::BUTTON_PADDING_V) + ->horizontal(self::BUTTON_PADDING_H) + ->toArray(), + ], + ], + ], + ], /** * ============================================ @@ -682,41 +766,6 @@ public function buildJsonData(CollectionInterface $collection): array // ->bottom( '0px' ), // ], // ], - 'core/button' => [ // .wp-block-button__link - 'border' => (new Border($collection)) - ->color(self::BUTTON_BORDER_COLOR) -// ->radius(\sprintf( -// 'calc(%s/3)', -// $collection->get(self::FONT_SIZE_BASE)->var() -// )) - ->radius((string)(new CalcExperimental( - $collection->get(self::FONT_SIZE_BASE)->var(), - '/', - '3' - ))) - ->style('solid') - ->width('2px') - ->toArray(), - 'color' => (new Color($collection)) - ->background(self::BUTTON_BG) - ->text(self::BUTTON_TEXT) - ->toArray(), - 'spacing' => [ - 'padding' => (new Spacing($collection)) - ->shorthand([self::BUTTON_PADDING]) - ->toArray(), - 'margin' => (new Spacing($collection)) - ->top(self::SPACER_M) - ->toArray(), - ], - 'typography' => (new Typography($collection)) - ->fontFamily(self::FONT_FAMILY_BASE) - ->fontSize(self::FONT_SIZE_BASE) - ->textDecoration('none') - ->textTransform('uppercase') - ->lineHeight(self::LINE_HEIGHT_S) - ->toArray(), - ], 'core/file' => [ // .wp-block-file 'spacing' => [ 'margin' => (new Spacing($collection)) @@ -956,6 +1005,25 @@ public function buildJsonData(CollectionInterface $collection): array ], ], ], - ]; + ]); + + $this->registerCollection($jsonData, $collection); + + return $jsonData->toArray(); + } + + /** + * @param ConfigInterface $jsonData + * @param CollectionInterface $collection + * @return void + */ + private function registerCollection(ConfigInterface $jsonData, CollectionInterface $collection): void + { + $jsonData->set('settings.color.palette', $collection->toArrayByCategory(Palette::CATEGORY)); + $jsonData->set('settings.color.gradients', $collection->toArrayByCategory(Gradient::CATEGORY)); + $jsonData->set('settings.color.duotone', $collection->toArrayByCategory(Duotone::CATEGORY)); + $jsonData->set('settings.typography.fontSizes', $collection->toArrayByCategory(FontSize::CATEGORY)); + $jsonData->set('settings.typography.fontFamilies', $collection->toArrayByCategory(FontFamily::CATEGORY)); + $jsonData->set('settings.custom', $collection->toArrayByCategory(Custom::CATEGORY)); } } diff --git a/src/bootstrap.php b/src/bootstrap.php index dce8c53..3db1a17 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -64,6 +64,8 @@ $view = new View( $finder ); /** + * https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/ + * @link https://developer.wordpress.org/themes/block-themes/converting-customizer-settings-to-block-patterns/ * * @param string $pattern_name Pattern name including namespace. * @param array $pattern_properties Array containing the properties of the pattern: title, diff --git a/theme.json b/theme.json index ba84993..a495f72 100644 --- a/theme.json +++ b/theme.json @@ -216,7 +216,7 @@ { "slug": "base", "name": "Base font size 16px", - "size": "clamp(1.125rem, 2vw, 1.5rem)" + "size": "clamp(1rem, 2vw, 1.5rem)" }, { "slug": "h1", @@ -291,6 +291,22 @@ "customStyle": true, "customWidth": true }, + "blocks": { + "core/button": { + "color": { + "custom": false + } + }, + "core/navigation": { + "color": { + "custom": false + } + } + }, + "layout": { + "contentSize": "var(--wp--custom--content-size)", + "wideSize": "var(--wp--custom--wide-size)" + }, "custom": { "contentSize": "clamp(16rem, 60vw, 60rem)", "wideSize": "clamp(16rem, 85vw, 70rem)", @@ -328,13 +344,16 @@ "bg": "var(--wp--preset--color--base)", "text": "var(--wp--preset--color--button-text-hover)", "borderColor": "transparent", - "borderRadius": "calc( var(--wp--preset--font-size--base) /4)", + "borderRadius": "calc(var(--wp--preset--font-size--base) / 3)", "hover": { "bg": "var(--wp--preset--color--button-bg-hover)", "text": "var(--wp--preset--color--button-text-hover)", "borderColor": "transparent" }, - "padding": " 0.25em 0.7em" + "padding": { + "h": "0.75em", + "v": "0.375em" + } }, "form": { "border": { @@ -350,22 +369,6 @@ "height": "calc( var(--wp--custom--spacer--base) * 5.3125 )" } } - }, - "blocks": { - "core/button": { - "color": { - "custom": false - } - }, - "core/navigation": { - "color": { - "custom": false - } - } - }, - "layout": { - "contentSize": "var(--wp--custom--content-size)", - "wideSize": "var(--wp--custom--wide-size)" } }, "styles": { @@ -377,7 +380,7 @@ "fontFamily": "var(--wp--preset--font-family--base)", "fontSize": "var(--wp--preset--font-size--base)", "fontStyle": "normal", - "fontWeight": "300", + "fontWeight": "400", "letterSpacing": "normal", "lineHeight": "var(--wp--custom--line-height--m)", "textDecoration": "none", @@ -399,6 +402,69 @@ } }, "elements": { + "button": { + "border": { + "color": "var(--wp--custom--button--border-color)", + "radius": "var(--wp--custom--button--border-radius)", + "style": "solid", + "width": "1px" + }, + "color": { + "background": "var(--wp--custom--button--bg)", + "text": "var(--wp--custom--button--text)" + }, + "spacing": { + "padding": { + "top": "var(--wp--custom--button--padding--v)", + "bottom": "var(--wp--custom--button--padding--v)", + "right": "var(--wp--custom--button--padding--h)", + "left": "var(--wp--custom--button--padding--h)" + } + }, + "typography": { + "fontFamily": "var(--wp--preset--font-family--base)", + "fontSize": "var(--wp--preset--font-size--base)", + "textDecoration": "none", + "lineHeight": "var(--wp--custom--line-height--s)" + }, + ":hover": { + "color": { + "background": "var(--wp--custom--button--hover--bg)", + "text": "var(--wp--custom--button--hover--text)" + }, + "border": { + "color": { + "text": "var(--wp--custom--button--hover--border-color)" + } + } + }, + ":focus": { + "color": { + "background": "var(--wp--custom--button--hover--bg)" + }, + "border": { + "color": { + "text": "var(--wp--custom--button--hover--border-color)" + } + }, + "outline": { + "color": "var(--wp--preset--color--body-color-300)", + "offset": "1px", + "style": "dotted", + "width": "1px" + } + }, + ":active": { + "color": { + "background": "var(--wp--custom--button--hover--bg)" + }, + "border": { + "color": { + "text": "var(--wp--custom--button--hover--border-color)" + } + } + } + }, "link": { "color": { "text": "var(--wp--preset--color--link-color)", @@ -450,6 +516,30 @@ } }, "blocks": { + "core/button": { + "variations": { + "outline": { + "border": { + "color": "var(--wp--preset--color--base)", + "radius": "var(--wp--custom--button--border-radius)", + "style": "solid", + "width": "1px" + }, + "color": { + "background": "var(--wp--preset--color--body-bg)", + "text": "var(--wp--preset--color--base)" + }, + "spacing": { + "padding": { + "top": "var(--wp--custom--button--padding--v)", + "bottom": "var(--wp--custom--button--padding--v)", + "right": "var(--wp--custom--button--padding--h)", + "left": "var(--wp--custom--button--padding--h)" + } + } + } + } + }, "core/site-title": { "color": { "text": "var(--wp--preset--color--heading-color)" @@ -552,36 +642,6 @@ "margin": "var(--wp--custom--spacer--m) 0 0px 0" } }, - "core/button": { - "border": { - "color": "var(--wp--custom--button--border-color)", - "radius": "calc(var(--wp--preset--font-size--base) / 3)", - "style": "solid", - "width": "2px" - }, - "color": { - "background": "var(--wp--custom--button--bg)", - "text": "var(--wp--custom--button--text)" - }, - "spacing": { - "padding": { - "top": "var(--wp--custom--button--padding)", - "right": "var(--wp--custom--button--padding)", - "bottom": "var(--wp--custom--button--padding)", - "left": "var(--wp--custom--button--padding)" - }, - "margin": { - "top": "var(--wp--custom--spacer--m)" - } - }, - "typography": { - "fontFamily": "var(--wp--preset--font-family--base)", - "fontSize": "var(--wp--preset--font-size--base)", - "textDecoration": "none", - "textTransform": "uppercase", - "lineHeight": "var(--wp--custom--line-height--s)" - } - }, "core/file": { "spacing": { "margin": {