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

Components: Fix responsive across elements with box-sizing removal #28489

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Components: Fix usage of box-sizing across the elements
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* DO NOT USE THIS TO OVERRIDE STYLES */
.theme {
renatoagds marked this conversation as resolved.
Show resolved Hide resolved
& * {
box-sizing: border-box;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useLayoutEffect, useRef } from 'react';
import styles from './globals.module.scss';
import { ThemeInstance, ThemeProviderProps } from './types';

export const typography = {
Expand Down Expand Up @@ -85,12 +86,16 @@ export const spacing = {

const globalThemeInstances: Record< string, ThemeInstance > = {};

const setup = ( root: HTMLElement, id: string ) => {
const setup = ( root: HTMLElement, id: string, withGlobalStyles?: boolean ) => {
const tokens = { ...typography, ...colors, ...borders, ...spacing };
for ( const key in tokens ) {
root.style.setProperty( key, tokens[ key ] );
}

if ( withGlobalStyles ) {
root.classList.add( styles.theme );
}

if ( ! id ) {
return;
}
Expand All @@ -108,7 +113,12 @@ const setup = ( root: HTMLElement, id: string ) => {
* @param {ThemeProviderProps} props - Component properties.
* @returns {React.ReactNode} ThemeProvider component.
*/
const ThemeProvider: React.FC< ThemeProviderProps > = ( { children = null, targetDom, id } ) => {
const ThemeProvider: React.FC< ThemeProviderProps > = ( {
children = null,
targetDom,
id,
withGlobalStyles = true,
} ) => {
const themeWrapperRef = useRef< HTMLDivElement >();

// Check whether the theme provider instance is already registered.
Expand All @@ -120,15 +130,15 @@ const ThemeProvider: React.FC< ThemeProviderProps > = ( { children = null, targe
}

if ( targetDom ) {
return setup( targetDom, id );
return setup( targetDom, id, withGlobalStyles );
}

if ( ! themeWrapperRef?.current ) {
return;
}

setup( themeWrapperRef.current, id );
}, [ targetDom, themeWrapperRef, isAlreadyProvided, id ] );
setup( themeWrapperRef.current, id, withGlobalStyles );
}, [ targetDom, themeWrapperRef, isAlreadyProvided, id, withGlobalStyles ] );

// Do not wrap when the DOM element target is defined.
if ( targetDom ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export type ThemeProviderProps = {
* Content
*/
children?: React.ReactElement;
/**
* Inser global/reset styles
*/
withGlobalStyles?: boolean;
};

export type ThemeInstance = {
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/jetpack-components",
"version": "0.27.0",
"version": "0.27.1-alpha",
"description": "Jetpack Components Package",
"author": "Automattic",
"license": "GPL-2.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
}

.notice {
box-sizing: border-box;
margin: 0;
padding: calc( var( --spacing-base ) * 2 ) calc( var( --spacing-base ) * 3 ) calc( var( --spacing-base ) * 2 ) calc( var( --spacing-base ) * 3 ); // 16px | 24px | 16px | 24px
font-size: 16px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
display: flex;
flex-direction: column;
box-shadow: 0 0 0 1px var( --jp-gray-10 ) inset;
box-sizing: border-box;

&.is-link {
background: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
height: 100%;
padding: calc( var( --spacing-base ) * 8 );
position: relative;
box-sizing: border-box;
}

.container {
Expand Down Expand Up @@ -72,7 +71,7 @@
height: auto;
white-space: normal;
}

&:global(.is-secondary):hover:not(:disabled) {
background-color: var( --jp-black );
color: var( --jp-white );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Components: Fix usage of box-sizing across the elements
2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-my-jetpack",
"version": "2.7.4",
"version": "2.7.5-alpha",
"description": "WP Admin page with information and configuration shared among all Jetpack stand-alone plugins",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/my-jetpack/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '2.7.4';
const PACKAGE_VERSION = '2.7.5-alpha';

/**
* Initialize My Jetpack
Expand Down