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 Box Shadow Component #44651

Closed
7 tasks done
Tracked by #33447
phil-sola opened this issue Oct 3, 2022 · 70 comments · Fixed by #46502
Closed
7 tasks done
Tracked by #33447

Add Box Shadow Component #44651

phil-sola opened this issue Oct 3, 2022 · 70 comments · Fixed by #46502
Assignees
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@phil-sola
Copy link

phil-sola commented Oct 3, 2022

What problem does this address?

So as of Gutenberg 14.1 and in the upcoming WordPress 6.1 release, there will be support added for themes to register box shadows for specific blocks within the theme.json file.

Similar to padding, margin, typography, etc. I feel like it would be beneficial to actually have a box shadow component either for importing from a package for custom blocks or supported in core blocks which would enable users to create the exact shadow effect they are looking for.

What is your proposed solution?

Adding a box-shadow component within one of the packages which can be imported for custom block development or supported in core blocks which would enable users to create the exact shadow effect they are looking for.

Something like the 'Customize shadows' section on the left in this link: (https://box-shadow.dev/)

Including horizontal, vertical, blur, spread, and colour.

I searched issues for 'box shadow' and 'box-shadow' and couldn't find anything on this, however, I know it might already be something being looked at, apologies if so.

Design

shadows
  • Shadow panel is empty by default.
  • Clicking + opens a menu where you can choose shadows from three categories:
  • When a preset is added;
    • Clicking the row will re-open the menu so you can switch to a different preset
    • Clicking the icon will remove the shadow
    • Clicking the unlink icon will detach the shadow properties, essentially switching from the preset to a custom shadow...
  • When custom shadow(s) are added;
    • Clicking a row will open a popover where you can edit the associated shadow properties.
    • Clicking + will add a new shadow to the stack
    • Clicking will allow you to save the custom shadow as a preset for future use

Tasks

@ndiego ndiego added the [Type] Enhancement A suggestion for improvement. label Oct 4, 2022
@Jabe64
Copy link

Jabe64 commented Oct 27, 2022

+1 for this 💯 It should be listed in #33447 too.

@dkjensen
Copy link

dkjensen commented Nov 5, 2022

+1

@jasmussen

This comment was marked as outdated.

@jasmussen jasmussen added the Needs Design Feedback Needs general design feedback. label Nov 14, 2022
@jasmussen
Copy link
Contributor

CC: @WordPress/gutenberg-design

@jasmussen jasmussen added the [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi label Nov 14, 2022
@paaljoachim
Copy link
Contributor

Hey Joen. It looks like a good start!

@madhusudhand
Copy link
Member

@jasmussen Thanks for the designs. They look great!

I mocked up controls for Angle and Depth instead of X-position and Y-position, as that seems more ergonomic.

I like this idea and I would like to believe, a formula should transform these values to X,Y (apply in CSS) and also reverse transform them without issues.
I will work on this transformation (formula) and provide more detailed feedback.

A preset shadow is applied by clicking the plus, this adds an Item on the right

I would like to imagine shadow presets to behave similar to colors.
There would be Default Shadows (defined in Gutenberg) and Theme Shadows (defined in theme.json)

And a shadow preset could be a combination of multiple shadows that create a unique effect.
e.g.
image
This is a result of two shadows box-shadow: 5px 5px 0px -2px #DDCFFF, 5px 5px #040DE1.

A theme should be able to define them in theme.json as follows.

{
    "settings": {
        "color": {},
        "shadows": [{
            "name": "Double lines",
            "slug": "double-lines",
            "value": "5px 5px 0px -2px #DDCFFF, 5px 5px #040DE1"
        }, {
            ...
        }]
    }
}

Long story short:

Because a preset can have multiple shadows and they become preset variables (based on the given slug), the UI experience for them should slightly be different.

Following are my thoughts:

  • The panel shows presets just like design suggests (but both default and theme shadows)
  • When a preset is clicked, it ads a single row (just like custom shadow), but it remains read-only
  • It indicated as preset and name comes from the theme.json.
  • There should be a new section under global styles, Styles -> Shadows (similar to editing the color palette) where they can be edited.

image

This way, a preset shadow can be applied to any block and changing it in the global settings would effect all the blocks.

Let me know your thoughts.

@jasmussen
Copy link
Contributor

I like this idea and I would like to believe, a formula should transform these values to X,Y (apply in CSS) and also reverse transform them without issues.

Thank you! If it becomes a headache, don't spend too much time on it, we can start simpler if need be. For example it hits me that it might not be possible to represent all box-shadow configurations with this setup, as the angle+depth components assume that the X and Y values will always be the same. We might need a different angle component, one that's more of a map/grid, for this to work 🤔

I would like to imagine shadow presets to behave similar to colors.
There would be Default Shadows (defined in Gutenberg) and Theme Shadows (defined in theme.json)
A theme should be able to define them in theme.json as follows.

Yes.

When a preset is clicked, it ads a single row (just like custom shadow), but it remains read-only

Thanks for surfacing this shortcoming. I don't think we should make a read-only preset, they should all be editable. But I'll need to think about how to best surface multiple stacked shadows in the panel when applying a preset. Let me return here with some new mockups!

There should be a new section under global styles, Styles -> Shadows (similar to editing the color palette) where they can be edited.

Working on this mockup made me realize a shortcoming of our current global styles. Right now you have Typography, Colors, Layout. Layout includes various values — margin and block spacing for Buttons, and border and border radius for Image. For both Typography and Color, these two blocks (Buttons, Image) have panel counterparts. But there's no counterpart in Global Styles for Dimensions and Border — those are put inside "Layout" instead.

And so I'm not sure we should add a new "Shadows" in Global Styles. I think we should either:

  1. Accept that Global Styles has a trio of Typography, Color, and Layout, and put "Shadows" under Layout.
  2. Change Global Styles so that it gets a new "Border & Shadows" section, as well as a "Dimensions" section, to match the panels present for each block. This would let the "Layout" section continue to exist for things like Group, which have a Layout panel, but it would also make the Layout section not become a junk drawer for things that don't fit in color or typography.

We should probably start with 1, as 2 has some compounding effects. What do you think?

@jasmussen
Copy link
Contributor

Having tinkered a bit with this now, it's clear that approach I had thought of with regards to layered shadows that I was thinking of, inspired by #39427, is unlikely to work for stacked shadows for us. Quite simply, the fact that a preset can contain all stacks, means the UI to control each layer, would need to be surfaced in the flyout. I think I need to explore an entirely different approach to the presets, which as already noted, felt like the weakest aspect. I'll need more time to think on this.

One question — I really like this shadow generator, which creates 3 shadows by default. Would it be possible to have something like that for the default editor? Then perhaps we could put advanced editing of each individual layer behind an toggle, that would let you edit each layer individually? Essentially any non-standard preset, such as the sharp square shadow in your example, would then become an "advanced" shadow.

@jasmussen
Copy link
Contributor

Based on explorations, I have some new concepts to share, that should hopefully be simpler for the first version.

I would imagine we could start with a preset-first design:

Managing drop shadows in Global Styles

  • Structure remains the same: Border & Shadow → Block name, click the plus to add a shadow, the default preset gets added by default.
  • Clicking the flyout now lets you pick between default and theme presets first, though, and presets are just text buttons like style variations, relying on the inspector preview.
  • A cog can let you edit a shadow using basic existing properties. Doing so collapses any stacked shadows into a single shadow, for simplicity.
  • We can even start this first version without any shadow editing controls at all, if that's simpler, just presets.
  • It would be useful to figure out whether we create a new section called "Border & Shadow" and move Border + Radius controls there (CC: @WordPress/gutenberg-design). As an alternative, I think we should put "Shadow" under "Layout", where Border and Radius live at the moment. This may be simplest for the first version.

A followup would be to enable shadows in the post editor:

Shadows in the inspector

  • I would think this necessitates a decision on how Global styles categories (Color, Typography, Layout) map to block panels (Color, Typography, Layout, Border, Dimensions), as noted above. They are close, but not quite the same, and we should avoid creating an entirely new panel just for shadows. So what's a good place to put shadow controls? This mockup suggests renaming the Border panel to "Border & Shadow".

Not for the first effort, but I think there's a fun opportunity tied to the UI for editing drop shadows. It is possible to create beautiful natural-looking shadows by stacking multiple shadows at various depths, and I would love for us to include an algorithm for doing this, which could potentially be controllable like this:

Longer term algo editing of shadows

It's not something for the near term, but once you're in the shadow editing control, we might as well provide excellent shadows by default.

What do you think? CC: @madhusudhand @scruffian

@jameskoster
Copy link
Contributor

This seems to work well. We could even double-down further on the presets, and save the user a click by surfacing them in the + menu:

shadow

This may work best with a dedicated section, similar to Figma's "Effects" panel. Perhaps that's worth considering if we intend to support filters and other similar features in the future.

@jasmussen
Copy link
Contributor

Nice, I can see further simplification work. Though I abandoned the idea of showing a shadow preset in that small 20x20 area in the ItemGroup, it simply didn't have space enough to be legible at that size, and there's a preview above, after all.

I'm not sure about the unlink, though: what what would the main action of the ItemGroup be?

@paaljoachim
Copy link
Contributor

This looks really good!

@jameskoster
Copy link
Contributor

I'm not sure about the unlink, though

I suppose an alternative would be a remove/delete action. But then you couldn't create a custom shadow from a preset base.

what what would the main action of the ItemGroup be?

Do you mean what happens on click? One option would be to just open the shadow menu:

Screenshot 2022-11-16 at 13 05 45

@richtabor
Copy link
Member

richtabor commented Nov 16, 2022

I like the idea of presets as well — we use them for font sizes, spacing, colors... may as well for shadows. Any reason why we wouldn't reuse the existing stepped range control pattern? And if the icon is pressed, you see a detailed edit view of that preset — basically like how border controls work.

And second, if we wanted to merge some of these panels, we could package them as tool belt items in an "Effects" panel. Border would fit in well for example.

CleanShot 2022-11-16 at 11 23 47@2x

Also it doesn't have to be integer based (maybe the slugs are, but not the label).

@jasmussen
Copy link
Contributor

I tend to think we should stick to the pattern of ItemGroups opening flyout menus, and since there's a preview in the canvas for the post editor, and in the top right of the inspector for global styles, the simple shadow icon feels like a better starting point to me. But perhaps we can follow the PR and see what feels right as we move closer?

And if the icon is pressed, you see a detailed edit view of that preset — basically like how border controls work.

Not sure I understand. Do you mean something like this?

control

While we could have presets inside that flyout, the unique challenge with shadows is that in theme.json you can apply a stacked shadow consisting of multiple separate definitions, and have that be a preset. That's why I ended up thinking the preset-first approach was the simplest way to start. Let me know if I missed a beat here!

Another aspect of the preset-first approach, is to enable the more creative uses of drop shadows like this example Madhu shared:

Any reason why we wouldn't reuse the existing stepped range control pattern?

My instinct would be that we need more finegrained control here. That said, I see where you're coming from — each step of the slider could theoretically represent a predefined elevation. It's the same instinct that led me towards this mockup, where I'm picturing each dot on the grid to be an "elevation slot", and then multiple stacked shadows are calculated based on the elevation, light position, and sliders. So you'd still have these predefined steps, but you'd also have directionality in the mix.

@madhusudhand
Copy link
Member

madhusudhand commented Nov 23, 2022

Great designs! 🎆

image image

The dropdown of shadow presets is missing the theme presets.
Can you accommodate both default and theme presets with labels may be?

And a question on how it should be invoked.
All the style sections use ToolsPanel that comes with options such as reset styles on click of vertical dots

image

Do you suggest to have a + button beside it? or a label like Add shadow as one of the option?

@jasmussen
Copy link
Contributor

@madhusudhand I'm not convinced we should go with the immediate dropdown, I still think it's best to use the ItemGroup with the flyout pattern that shows "Default" and "Theme" presets using the same buttons as are present in the Styles panel. We can omit the "Settings" icon for now though.

That would make the shadow control a single control for now, so not yet any stacked shadows. I'm unsure yet how to best surface such stacked shadows, but I'm leaning towards if we ever do that, it should probably be inside the flyout, because presets themselves can come as stacked definitions.

@madhusudhand
Copy link
Member

madhusudhand commented Nov 23, 2022

That would make the shadow control a single control for now, so not yet any stacked shadows.

That will be a good start from UI perspective.

For context, a stacked shadow need not be always from a preset.
A theme developer can define stacked shadow for a button only (not a theme preset) in theme.json and it is a custom stacked shadow. In such scenarios, how should we represent that a shadow is applied to the block?

image

In the first step, because edit controls aren't there, UI should somehow indicate that a custom shadow is applied, because setting it from theme.json is already possible.

Eventually, it should work bi-directional.
Set a custom or preset shadow (single or stacked) from the UI.
Parse a custom or preset shadow from theme.json and show in UI. Let users edit that.

I'm leaning towards if we ever do that, it should probably be inside the flyout, because presets themselves can come as stacked definitions.

I am not sure if it is best to edit the presets (global in nature) from button styles panel.
User might think that shadow they are editing is for the button, but because the presets are global, they can effect all other blocks that are using it.

But in other perspective, a user might want to do minor tweaks to the preset shadow, and apply to the button.
I guess, on edit, it is best if the preset is copied as custom shadow, and apply to the block.

I am thinking for color, I cannot change default or theme palette colors such as Primary from a button styles panel.
I would have to edit them from global styles -> colors only because they effect everything.

@jasmussen
Copy link
Contributor

For context, a stacked shadow need not be always from a preset.
A theme developer can define stacked shadow for a button only (not a theme preset) in theme.json and it is a custom stacked shadow. In such scenarios, how should we represent that a shadow is applied to the block?

I'm assuming this shadow definition would come from theme.json directly? Good question. We probably need an interface for this, but for the near future, would it make sense to add a "Default" button to the "Theme" section, which embodied this?

I am not sure if it is best to edit the presets (global in nature) from button styles panel.
User might think that shadow they are editing is for the button, but because the presets are global, they can effect all other blocks that are using it.

Oh I'm not talking about editing the presets here, that's probably a separate thing and more related to #44417. Let me know if I misunderstood something here.

So that is to say, I can understand we need to be able to both apply a preset to a block, and add an entirely custom shadow to a block, and that we need to be able to do this both locally on a per-block basis, and globally to apply by default across all buttons, for example. Right?

@seothemes
Copy link

This is looking really good. Here's a few important things to consider for box shadows that I haven't seen mentioned:

  • Hover state
  • Theme.json defaults
  • Inset value

This a screen recording of how each is handled in the Blockify theme:

box-shadow-hover.mov

Changing just one of the values will enable a box shadow and inherit the remaining values from the theme. This also applies to the Hover state which inherits from the Default state for values that are not set.

We should also consider adding support for Inset values from the beginning too, as that could be difficult to add in the future.

@madhusudhand
Copy link
Member

So that is to say, I can understand we need to be able to both apply a preset to a block, and add an entirely custom shadow to a block, and that we need to be able to do this both locally on a per-block basis, and globally to apply by default across all buttons, for example. Right?

Thats correct. It would be the final goal.

@mtias mtias mentioned this issue Dec 5, 2022
57 tasks
@madhusudhand
Copy link
Member

madhusudhand commented Dec 15, 2023

@annezazu annezazu moved this from ❓ Triage to 🗣️ In Discussion / Needs Decision in WordPress 6.5 Editor Tasks Jan 5, 2024
@vcanales
Copy link
Member

vcanales commented Jan 18, 2024

Status update

Created a PR to test block supports after #57101 is merged: #57982

@colorful-tones
Copy link
Member

Hey folks,
I wanted to check in to see what is left for this to be ready for 6.5? It looks to be quite close from what I can tell.

Are we looking for more testing or adding in more block supports?

I’m also wondering if we could remove the Needs Design Feedback label? It seems it is beyond that point. 🤔

Thanks for the excellent progress.

@madhusudhand madhusudhand removed the Needs Design Feedback Needs general design feedback. label Feb 2, 2024
@madhusudhand
Copy link
Member

wanted to check in to see what is left for this to be ready for 6.5? It looks to be quite close from what I can tell.

We targeted enabling shadow support for more blocks in addition to button block and in block styles. We are addressing some feedback about the placement of the control here

@annezazu
Copy link
Contributor

annezazu commented Feb 5, 2024

Removing this issue from 6.5 after confirming the two PRs are listed within the board #57103 & #57101 as this is more of an overview issue of the work than task based at this point.

@bph
Copy link
Contributor

bph commented Feb 16, 2024

I have been testing the state of box shadow in 6.5 Beta also with shadow presets from the theme.json and I was wondering how I could remove the core box shadow preset?
Screenshot 2024-02-16 at 13 23 41

In the screenshot the first five are coming from core, the custom presets start with the red one. I'd like to not offer too many choices, and remove either all of core presets or single ones.

Should i create an issue for that or is it already built in?

@carolinan
Copy link
Contributor

@bph There is a pull request for opting in or or out via theme.json #58766

@bph
Copy link
Contributor

bph commented Feb 16, 2024

Thank you @carolinan

@richtabor richtabor added the [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. label Mar 21, 2024
@jameskoster
Copy link
Contributor

I updated the 'Design' section of the OP with some updated mockups based on the ongoing work in #57100.

@jasmussen jasmussen moved this from Now to In Dev in Design priorities May 2, 2024
@madhusudhand
Copy link
Member

Shadows can now be created/edited in the editor.
Marking this issue as complete. 🎉

@github-project-automation github-project-automation bot moved this from 📥 Todo to ✅ Done in WordPress 6.6 Editor Tasks May 25, 2024
@github-project-automation github-project-automation bot moved this from In Dev to Done in Design priorities May 25, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Gutenberg Phase 2: Customization May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
Status: Done
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.