Skip to content

Conversation

@cchaos
Copy link
Contributor

@cchaos cchaos commented Apr 28, 2022

These added utilities are some of the most commonly used/re-used properties among EUI and consumer styles.

Logical properties

These help convert standard direction properties like left, height, and margin-bottom into logical properties like inline-start, inset-block, and margin-block-end.

Docs lives under Theming/SIze: https://eui.elastic.co/pr_5850/#/theming/sizing#utilities

**NOTE: ** I did not prefix these helpers with eui because they're generic and not specific to EUI in any way.

  • logicals{}: Map of all the directional properties to the logical counterpart
  • logicalCSS(): Function to return the string version of the property: value pair
  • logicalStyle(): Function to return the object version of the property: value pair
  • logicalTextAlign(): Text-specific function because it's the value that needs to change not the property

Padding

These helpers either create the full map of common padding sizes (styles function) including logical side or quickly grab one of the pre-defined padding attributes based on side and size (hook).

Docs lives under Theming/Size: https://eui.elastic.co/pr_5850/#/theming/sizing#utilities

  • euiPaddingSize(): Returns the calculated padding size value only
  • useEuiPaddingSize(): Hook version of ^^
  • useEuiPaddingStyles(): Returns the full map of size to padding value for quick styling of components that can have their padding size changed via a prop. It also accepts a side that will update the property based on the logical property equivelant.

Background color

Similar to the padding functions, these create maps specifically around colorizing background colors based off the brand colors (lightly shaded versions). It's similar to how EuiPanel colors it's background but now in a re-usable style fashion.

Docs lives under Theming/Color: https://eui.elastic.co/pr_5850/#/theming/colors#utilities

  • euiBackgroundColor(): just calculates and returns the color
  • useEuiBackgroundColor(): Hook that returns the string version calculated color
  • useEuiBackgroundColorStyles(): Returns the full map of token to background-color: value pair for quick styling of components that can have their background color changed via a prop

Contrast specific docs added to the bottom of the contrast tab.

Screen Shot 2022-05-02 at 01 13 26 AM

Checklist

  • Checked in both light and dark modes
  • [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • [ ] Props have proper autodocs and playground toggles
  • Added documentation
  • [ ] Checked Code Sandbox works for any docs examples
  • [ ] Added or updated jest and cypress tests
  • [ ] Checked for breaking changes and labeled appropriately
  • [ ] Checked for accessibility including keyboard-only and screenreader modes
  • Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

Comment on lines -30 to 33
quarter: css`
width: 25%;
margin-inline: auto;
${logicalCSS('width', '25%')}
${logicalCSS('margin-horizontal', 'auto')}
`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've started updating some properties, but at the end of the day, if we know/remember the logical property as we see below with margin-block it's somewhat easier to read. So I 🤷‍♀️ about whether we need to use these helpers everywhere or not. The two arguments I see for using the util are:

  1. Future proof readability for folks not fully knowledgable of the new properties
  2. If the CSS spec ever changes, we have one place we need to update (least likely scenario at this point)


export type EuiBackgroundColor = typeof BACKGROUND_COLORS[number];

export const euiBackgroundColorStyles = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically the generic equivalent/conversion of $euiPanelBackgroundColorModifiers

export const PADDING_SIZES = ['none', 'xs', 's', 'm', 'l', 'xl'] as const;
export type EuiPaddingSize = typeof PADDING_SIZES[number];

export const euiPaddingStyles = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically the generic equivalent/conversion of $euiPanelPaddingModifiers

@cchaos cchaos marked this pull request as ready for review April 28, 2022 14:07
@cchaos
Copy link
Contributor Author

cchaos commented Apr 28, 2022

Ready for review 😄

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@elizabetdev elizabetdev self-requested a review April 28, 2022 17:34
@cchaos
Copy link
Contributor Author

cchaos commented Apr 28, 2022

I took another page out of @constancecchen's book (i.e. copied her work) and created tests for these utils. This is a great method also to quickly compare the values of every acceptable parameter (and makes it easy for me to update Figma 😉 )

_might as well :)_
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

cchaos added 5 commits May 1, 2022 23:45
- `euiBackgroundColorStyles` is now a hook version: `useEuiBackgroundColorStyles`
- Added table of values in docs section
- Added specific contrast section
- `euiPaddingSize` just passes back the value
- `useEuiPadding` is the hook version
- `useEuiPaddingStyles` is the hook that passes back the entire object
- Fixed the value for size `m` to be `base` not `m`
- Fixed up tests and docs
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@cchaos
Copy link
Contributor Author

cchaos commented May 2, 2022

I think I've addressed all concerns. Thank you both! 💟

P.S. I'll update the docs' sections with parameter types when #5855 merges to utilize the new ThemeValue prop added there.

@cchaos cchaos requested a review from cee-chen May 2, 2022 23:49
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

@cee-chen
Copy link
Contributor

cee-chen commented May 3, 2022

Oh no! I'm not sure what's going wrong, but it looks like Emotion isn't rendering the expected output on https://eui.elastic.co/pr_5850/#/display/avatar 😬

Maybe it's the semi-colons following the mixin usage? I'm not actually sure they should be included when returning an object

EDIT: Yeah I think it's the semi-colons. https://eui.elastic.co/pr_5850/#/layout/horizontal-rule works and it has no trailing semi-colons.

@cchaos
Copy link
Contributor Author

cchaos commented May 3, 2022

Womp womp. It's not just the semicolons. It seems passing back an object expects it to be very precisely applied. After removing them, I still got the following css output:

    overflow-block: hidden;
    font-weight: 500;
    [object Object] [object Object] line-height: calc(16px * 4);

It's because of the extra wrapping function that was supposed to just return a string:

return `
${logicalStyle('width', size)};
${logicalStyle('height', size)};

I can change this particular instance to return a serialized string, but I think we may run into this more often than not since we're trying to always return strings.

That's why I think optimizing for the string value is better than optimizing for the object. Still begs the question though of whether we need to have two mixins per.

@cee-chen
Copy link
Contributor

cee-chen commented May 3, 2022

D'oh. Totally makes sense. I'd be good with consistently returning strings personally. I do think we should prefer to pick 1 or the other for developer experience. @thompsongl any thoughts here?

@cee-chen
Copy link
Contributor

cee-chen commented May 3, 2022

Per our sync today, I'd be good with reverting ded07ab and shipping this PR with both string and object utils!

cchaos and others added 8 commits May 3, 2022 13:23
This reverts commit 29c6642.
Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: naveen <[email protected]>
* Commented out some unused (yet) properties and updated the Focus docs section
* Make `focus` global token required
* Updated ThemeExamples code snippets to scroll horizontally

* [EuiSplitPanel] Fix border-radius of nested split panels
# Conflicts:
#	src/global_styling/mixins/index.ts
# Conflicts:
#	src/global_styling/mixins/index.ts
@cchaos
Copy link
Contributor Author

cchaos commented May 3, 2022

Sorry about the commit history, but this PR should be up to date now based on the discussion. 😅

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

🎉

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

1 similar comment
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5850/

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@cchaos cchaos merged commit 1c780b1 into elastic:main May 4, 2022
@cchaos cchaos deleted the css-in-js/utils branch May 4, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants