-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style Engine: add typography and color to frontend (#40665)
* Returning inline styles by default. * Adding some dev notes for later brain * Adding a couple of typography styles Updating tests Refactor styles directory * Adding text decoration Fixing camel case style prop name * Adding typography properties letterSpacing.ts and textTransform.ts * Adding color.text and typography.fontWeight * Refactor generic rule generator * Experiment: adding classname generator * Fixing bonkers typos because I copy and paste like I just don't care. It's my PR and I'll fail if I want to. Preferencing `uniq` for new Set() spread Updating tests. * Enable style engine for backgroundColor * Regenerate pullquote fixture since the style engine changes the order of the inline styles rules. Nothing major. * Add constants Updated inline docs Making the generateRule signature the same as generateBoxRules * Update packages/style-engine/src/index.ts Co-authored-by: Andrew Serong <[email protected]> * Refactoring generate method to split inline and selector logic Removing styles color text support because we haven't yet come up a with a way to deal with link color styles for elements. We need to reconcile the way we generate text colors with link css var colors and the logic in hooks/style.js Add constants Updated inline docs Making the generateRule signature the same as generateBoxRules * Remove TODO comment. It's something we can do in the future, but it doesn't need to pollute the codebase. * Reinstating color and now parsing style value for `var:`, whereby we'd return CSS vars all the time. * A bit of defensive coding to check for a string type * Testing out generating block color classnames using the style engine. * Also passing the style color value to `getClassnames` so it will add the generic class name if required. Regenerating fixtures due to the re-ordering of color classnames. * Reverting `getClassnames`. It's a bigger change and should be looked at in another PR. * Fix typo in fixture * Flag fontStyle with useEngine: true so that it uses the style engine. Remove the handler for fontFamily to reflect the current situation in the editor whereby no custom fontFamily style values are expected. Removed unused function `getSlugFromPreset` Added tests for elements.link.color.text preset style values. Co-authored-by: Andrew Serong <[email protected]>
- Loading branch information
1 parent
14c0c1d
commit 1eee465
Showing
19 changed files
with
385 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Style, StyleOptions } from '../../types'; | ||
import { generateRule } from '../utils'; | ||
|
||
const background = { | ||
name: 'background', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'color', 'background' ], | ||
'backgroundColor' | ||
); | ||
}, | ||
}; | ||
|
||
export default background; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Style, StyleOptions } from '../../types'; | ||
import { generateRule } from '../utils'; | ||
|
||
const gradient = { | ||
name: 'gradient', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'color', 'gradient' ], | ||
'background' | ||
); | ||
}, | ||
}; | ||
|
||
export default gradient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import background from './background'; | ||
import gradient from './gradient'; | ||
import text from './text'; | ||
|
||
export default [ text, gradient, background ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Style, StyleOptions } from '../../types'; | ||
import { generateRule } from '../utils'; | ||
|
||
const text = { | ||
name: 'text', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( style, options, [ 'color', 'text' ], 'color' ); | ||
}, | ||
}; | ||
|
||
export default text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const VARIABLE_REFERENCE_PREFIX = 'var:'; | ||
export const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|'; | ||
export const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import padding from './padding'; | ||
import margin from './margin'; | ||
import color from './color'; | ||
import spacing from './spacing'; | ||
import typography from './typography'; | ||
|
||
export const styleDefinitions = [ margin, padding ]; | ||
export const styleDefinitions = [ ...color, ...spacing, ...typography ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import padding from './padding'; | ||
import margin from './margin'; | ||
|
||
export default [ margin, padding ]; |
4 changes: 2 additions & 2 deletions
4
packages/style-engine/src/styles/margin.ts → ...style-engine/src/styles/spacing/margin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/style-engine/src/styles/padding.ts → ...tyle-engine/src/styles/spacing/padding.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Style, StyleOptions } from '../../types'; | ||
import { generateRule } from '../utils'; | ||
|
||
const fontSize = { | ||
name: 'fontSize', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'fontSize' ], | ||
'fontSize' | ||
); | ||
}, | ||
}; | ||
|
||
const fontStyle = { | ||
name: 'fontStyle', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'fontStyle' ], | ||
'fontStyle' | ||
); | ||
}, | ||
}; | ||
|
||
const fontWeight = { | ||
name: 'fontWeight', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'fontWeight' ], | ||
'fontWeight' | ||
); | ||
}, | ||
}; | ||
|
||
const letterSpacing = { | ||
name: 'letterSpacing', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'letterSpacing' ], | ||
'letterSpacing' | ||
); | ||
}, | ||
}; | ||
|
||
const lineHeight = { | ||
name: 'letterSpacing', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'lineHeight' ], | ||
'lineHeight' | ||
); | ||
}, | ||
}; | ||
|
||
const textDecoration = { | ||
name: 'textDecoration', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'textDecoration' ], | ||
'textDecoration' | ||
); | ||
}, | ||
}; | ||
|
||
const textTransform = { | ||
name: 'textTransform', | ||
generate: ( style: Style, options: StyleOptions ) => { | ||
return generateRule( | ||
style, | ||
options, | ||
[ 'typography', 'textTransform' ], | ||
'textTransform' | ||
); | ||
}, | ||
}; | ||
|
||
export default [ | ||
fontSize, | ||
fontStyle, | ||
fontWeight, | ||
letterSpacing, | ||
lineHeight, | ||
textDecoration, | ||
textTransform, | ||
]; |
Oops, something went wrong.