Conversation
chrisgervang
left a comment
There was a problem hiding this comment.
Deck's DOM structure can vary depending on the environment, but I'm assuming this is much is always true:
<deck-root <!-- deck's style prop -->>
<widget-container>
<view-container <!-- class='dark-theme' is applied here -->>
<widget <!-- widget's style prop -->/>
</view-container>
<!-- other views -->
</widget-container>
</deck-root>ThemeWidget is close but is ambiguous about an important behavior: Does the widget's theme apply to all widgets or just the widget's neighboring it within the same view? dark-theme's position in the DOM implies the latter, but querySelectorAll implies the former.
I discuss how either could be implemented in my comments, but I'm in favor of the the simpler direction: apply the theme to all widgets (<widget-container>).
I think it's important that this widget follows CSS cascading norms.. Namely,
deck.setProps({ style: ...})cannot overwrite what this widget sets, because this widgets are lower in the hierarchy then the deck root.- but a widget's style prop should overwrite what this widget sets. (e.g.
new FullscreenWidget({ style: ... })would overwrite theThemeWidget's effect on itself.
| /** | ||
| * A Deck Theme is a set of CSS variables that control CSS styling of the official widgets. | ||
| */ | ||
| export type DeckWidgetTheme = { |
| this.deck?.setProps({ | ||
| style: this.darkMode ? this.props.darkModeTheme : this.props.lightModeTheme | ||
| }); |
There was a problem hiding this comment.
| this.deck?.setProps({ | |
| style: this.darkMode ? this.props.darkModeTheme : this.props.lightModeTheme | |
| }); |
We shouldn't set deck props in widgets (user's will overwrite it).
There was a problem hiding this comment.
We shouldn't set deck props in widgets (user's will overwrite it).
Let's sort that out in a second PR
|
|
||
| The `id` must be unique among all your widgets at a given time. It's recommended to set `id` explicitly if you have multipe widgets of a given thpe. | ||
|
|
||
| #### `placement` (string, optional) {#placement} |
There was a problem hiding this comment.
Just a note of context: Similar to FullscreenWidget, if we're deciding themes apply to all widgets then we'd omit the viewId prop (leave this as-is).
viewId is on compass and zoom widgets to scope the widget to a specific view, useful to get unique controls when you have a MapView side-by-side with a GlobeView, for example.
There was a problem hiding this comment.
Just a note of context: Similar to
FullscreenWidget, if we're deciding themes apply to all widgets then we'd omit theviewIdprop (leave this as-is).
Yes, I am going with the global theme approach.
(For what its worth. I was initially incorrectly assuming the viewId allowed the user to position the widget in a certain view. Perhaps a potential point of confusion for users.)
There was a problem hiding this comment.
viewId does position it, and that could be all it does.
So far though I haven't seen feedback to indicate the need for position global widgets (Fullscreen, Screenshot, and Theme)
| this.element = el; | ||
| this.update(); | ||
| return el; | ||
| } |
There was a problem hiding this comment.
Insert initialTheme's effect in onAdd?
There was a problem hiding this comment.
Insert
initialTheme's effect inonAdd?
Not sure I understand.
| render(ui, element); | ||
| } | ||
|
|
||
| setProps(props: Partial<ThemeWidgetProps>) { |
There was a problem hiding this comment.
If we decide to scope the theme, ThemeWidget#setProps would need to account for the widget moving views. We'd need to unset all of the theme variables on the old view, and apply them in the new one.
Needless to say, it's simpler to just apply themes equally to all widgets.
There was a problem hiding this comment.
Needless to say, it's simpler to just apply themes equally to all widgets.
We are going with global themes.
Co-authored-by: Chris Gervang <chrisgervang@users.noreply.github.com>
Co-authored-by: Chris Gervang <chrisgervang@users.noreply.github.com>
ibgreen
left a comment
There was a problem hiding this comment.
Addressed the comments that do not relate directly to the mechanics of updating the CSS variables.
One change I made is that I moved the documentation of widget specific CSS variables (currently just icons) into each widget doc.
I feel that the variables associated with the theme should just be the general variables.
We can still have CSS variables for each widget to allow some extra control but they should specific to the widget (I would prefer if they were also scoped to the widgets).
|
|
||
| The `id` must be unique among all your widgets at a given time. It's recommended to set `id` explicitly if you have multipe widgets of a given thpe. | ||
|
|
||
| #### `placement` (string, optional) {#placement} |
There was a problem hiding this comment.
Just a note of context: Similar to
FullscreenWidget, if we're deciding themes apply to all widgets then we'd omit theviewIdprop (leave this as-is).
Yes, I am going with the global theme approach.
(For what its worth. I was initially incorrectly assuming the viewId allowed the user to position the widget in a certain view. Perhaps a potential point of confusion for users.)
| viewContainer.style.pointerEvents = 'none'; | ||
| viewContainer.style.position = 'absolute'; | ||
| viewContainer.style.overflow = 'hidden'; | ||
| viewContainer.classList.add('deck-theme'); |
There was a problem hiding this comment.
But if we instead are deciding we want themes to apply to all widgets, we'd instead add
I will leave this for a second PR as I have additional thoughts on it and focus on getting the rest of this PR clean
| this.element = el; | ||
| this.update(); | ||
| return el; | ||
| } |
There was a problem hiding this comment.
Insert
initialTheme's effect inonAdd?
Not sure I understand.
| render(ui, element); | ||
| } | ||
|
|
||
| setProps(props: Partial<ThemeWidgetProps>) { |
There was a problem hiding this comment.
Needless to say, it's simpler to just apply themes equally to all widgets.
We are going with global themes.
| this.deck?.setProps({ | ||
| style: this.darkMode ? this.props.darkModeTheme : this.props.lightModeTheme | ||
| }); |
There was a problem hiding this comment.
We shouldn't set deck props in widgets (user's will overwrite it).
Let's sort that out in a second PR
| // Note: deck does not support updating the style property | ||
| // this.deck?.setProps({ | ||
| // style: themeStyle | ||
| // }); | ||
| const elements = document.querySelectorAll('.deck-theme'); |
There was a problem hiding this comment.
I think closest is what we want to use from within a widget.
Agreed but will leave this for second PR to avoid bike shedding here.
chrisgervang
left a comment
There was a problem hiding this comment.
Stamping so we can experimentally merge this in. To graduate I'll take a pass on CSS mechanics.
| .deck-theme { | ||
| --widget-margin: 12px; | ||
| --button-stroke: rgba(255, 255, 255, 0.3); | ||
| --button-corner-radius: 8px; | ||
| --button-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.25); | ||
| --button-size: 28px; | ||
| --button-background: #616166; | ||
| --button-backdrop-filter: unset; | ||
| --button-inner-stroke: unset; | ||
| --button-icon-hover: rgb(24, 24, 26); | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't want to maintain this approach. It's another source of truth that can get out of sync, and is redundant to the JS definitions
44087a1 to
a41dff5
Compare
Closes #
Background
Change List
Note: Setting the themes using Deck level styles has no effect. My hypothesis is that the theme variables are too nested under specific classes?