Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a theme that uses the latest block style system + block templates #39

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions colorful/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Colorful

Colorful is an experimental WordPress theme that uses the [Block Style System](https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/themes/theme-json.md) and [Block Templates](https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/themes/block-based-themes.md) to create a minimal theme demo.

## What's here

```
colorful
|__ block-templates
|__ index.html
|__ experimental-theme.json
|__ functions.php
|__ style.css
```

## Requirements

- Gutenberg plugin as of [a271af4872](https://github.com/WordPress/gutenberg/tree/a271af487eb8e04945048cca856c211454b6e56c)
- FSE experiment enabled
1 change: 1 addition & 0 deletions colorful/block-templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:post-content /-->
99 changes: 99 additions & 0 deletions colorful/experimental-theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"global": {
"presets": {
"color": [
{
"slug": "foreground",
"value": "#313131"
},
{
"slug": "background",
"value": "#FFDE69"
},
{
"slug": "primary",
"value": "#022384"
},
{
"slug": "secondary",
"value": "#DB403B"
}
],
"font-size": [
{
"slug": "small",
"value": "12px"
},
{
"slug": "medium",
"value": "16px"
},
{
"slug": "large",
"value": "50px"
}
],
"line-height": [
{
"slug": "small",
"value": "1.3"
},
{
"slug": "medium",
"value": "1.3"
},
{
"slug": "large",
"value": "1.4"
}
],
"font-family": [
{
"slug": "primary",
"value": "'Jost', sans-serif"
},
{
"slug": "secondary",
"value": "'Lora', serif"
}
],
"gradient": [
]
},
"features": {
"typography": {
"dropCap": false
}
}
},
"core/paragraph": {
"styles": {
"color": {
"text": "var(--wp--preset--color--foreground )"
},
"typography": {
"fontSize": "var( --wp--preset--font-size--medium )"
}
}
},
"core/heading/h1": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I see how this does anything. Removing it does not change anything relating to the output or color of an H1 tag. @jffng Would you be able to help me understand what this is doing? 🙏

Screen Shot 2020-06-19 at 1 48 08 PM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I haven't been able to get this part to work either (both here and in another theme I tried this with).

Copy link
Collaborator Author

@jffng jffng Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API changed since I first opened this PR. Just pushed some changes that should address it, tested on GB 8.3.

"styles": {
"color": {
"text": "var( --wp--preset--color--primary )"
},
"typography": {
"fontSize": "var( --wp--preset--font-size--large )"
}
}
},
"core/heading/h2": {
"styles": {
"color": {
"text": "var( --wp--preset--color--primary )"
},
"typography": {
"fontSize": "28px"
}
}
}
}
89 changes: 89 additions & 0 deletions colorful/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

if ( ! function_exists( 'colorful_theme_setup' ) ) :
/**
* Initialize the theme supports.
*/
function colorful_theme_setup() {
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );

// Alignwide and alignfull classes in the block editor.
add_theme_support( 'align-wide' );

// Adding support for core block visual styles.
add_theme_support( 'wp-block-styles' );

// Adding support for responsive embedded content.
add_theme_support( 'responsive-embeds' );

// Adding support for editor styles.
add_theme_support( 'editor-styles' );

// Enqueue stylesheet for the editor.
add_editor_style( get_stylesheet_uri() );

// Editor color palette.
// All of these values will be overridden by the theme.json's global => preset => colors array.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Foreground', 'colorful' ),
'slug' => 'foreground',
'color' => '#313131',
),
array(
'name' => __( 'Background', 'colorful' ),
'slug' => 'background',
'color' => '#FFDE69',
),
array(
'name' => __( 'Primary', 'colorful' ),
'slug' => 'primary',
'color' => '#022384',
),
array(
'name' => __( 'Secondary', 'colorful' ),
'slug' => 'secondary',
'color' => '#DB403B',
)
)
);

// Editor font sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => __( 'Small', 'colorful' ),
'shortName' => __( 'S', 'colorful' ),
'size' => 12,
'slug' => 'small',
),
array(
'name' => __( 'Normal', 'colorful' ),
'shortName' => __( 'M', 'colorful' ),
'size' => 16,
'slug' => 'normal',
),
array(
'name' => __( 'Large', 'colorful' ),
'shortName' => __( 'L', 'colorful' ),
'size' => 50,
'slug' => 'large',
),
)
);
}
endif;
add_action( 'after_setup_theme', 'colorful_theme_setup' );

/**
* Enqueue scripts and styles.
*/
function colorful_theme_blocks_scripts() {
$theme_version = wp_get_theme()->get( 'Version' );
wp_enqueue_style( 'colorful-theme-blocks-styles', get_stylesheet_uri(), array(), $theme_version );
}
add_action( 'wp_enqueue_scripts', 'colorful_theme_blocks_scripts' );
1 change: 1 addition & 0 deletions colorful/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// this can be empty
117 changes: 117 additions & 0 deletions colorful/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Theme Name: Colorful
Text Domain: colorful
Version: 0.1
Requires at least: 5.3
Description: A test theme using the experimental WordPress global styles system.
Author: Jeff Ong
Author URI: https://jffng.com/
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

All files, unless otherwise stated, are released under the GNU General Public
License version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html)

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned
with others.
*/

@import url('https://fonts.googleapis.com/css2?family=Jost:wght@500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lora:wght@500&display=swap');

html {
font-size: 16px;
}

body {
background-color: var( --wp--preset--color--background );
font-family: var(--wp--preset--font-family--primary);
margin: 0;
overflow-x: hidden;
padding: 0;
}

p {
font-family: var(--wp--preset--font-family--primary);
line-height: var(--wp--preset--line-height--medium);
}

p.has-small-font-size {
font-size: var(--wp--preset--font-size--small);
line-height: var(--wp--preset--line-height--small);
}

p.has-medium-font-size {
font-size: var(--wp--preset--font-size--medium);
line-height: var(--wp--preset--line-height--medium);
}

p.has-large-font-size {
font-size: var(--wp--preset--font-size--large);
line-height: var(--wp--preset--line-height--large);
}

/* Support editor custom colors */
.has-primary-background-color {
background-color: var( --wp--preset--color--primary );
}

.has-secondary-background-color {
background-color: var( --wp--preset--color--secondary );
}

.has-foreground-background-color {
background-color: var(--wp--preset--color--foreground);
}

.has-background-background-color {
background-color: var( --wp--preset--color--background );
}

.has-background-color {
color: var( --wp--preset--color--primary );
}

.has-secondary-color {
color: var( --wp--preset--color--secondary );
}

.has-foreground-color {
color: var(--wp--preset--color--foreground);
}

.has-background-color {
color: var( --wp--preset--color--background );
}

.entry-content > * {
margin: 0 auto;
max-width: 580px; /* Match the block editor styles */
}

.alignwide {
margin: 0 auto;
max-width: 1070px;
}

.alignfull {
margin: 0;
max-width: 100%;
}

.alignwide, .alignfull {
padding: 0 12px;
}

.wp-block-navigation.is-style-light:not(.has-background) .wp-block-navigation__container, .wp-block-navigation:not(.has-background) .wp-block-navigation__container {
background-color: var( --wp--preset--color--background );
}

.wp-block-navigation-link__label {
color: var( --wp--preset--color--secondary );
font-family: var(--wp--preset--font-family--primary);
font-size: var(--wp--preset--font-size--medium);
line-height: var(--wp--preset--line-height--medium);
text-transform: uppercase;
}