Skip to content

Commit 61a1622

Browse files
authored
Fix missing stack-item headerColor and realm-icon border properties (#2038)
* fix missing headerColor and realm-icon border properties * rev change * add test * update test
1 parent f905812 commit 61a1622

File tree

4 files changed

+96
-38
lines changed

4 files changed

+96
-38
lines changed

packages/boxel-ui/addon/src/components/card-header/index.gts

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { concat } from '@ember/helper';
21
import { on } from '@ember/modifier';
32
import Component from '@glimmer/component';
43
import type { ComponentLike } from '@glint/template';
@@ -37,33 +36,27 @@ export default class CardHeader extends Component<Signature> {
3736
get safeMoreOptionsMenuItems() {
3837
return this.args.moreOptionsMenuItems || [];
3938
}
40-
get headerColor() {
41-
return (
42-
this.args.headerColor ||
43-
getComputedStyle(document.documentElement).getPropertyValue(
44-
'--boxel-light',
45-
)
46-
);
47-
}
4839
<template>
4940
<header
5041
data-test-card-header
5142
class={{cn is-editing=(bool @onFinishEditing)}}
5243
{{setCssVar
53-
boxel-card-header-background-color=this.headerColor
54-
boxel-card-header-text-color=(getContrastColor this.headerColor)
44+
boxel-card-header-background-color=@headerColor
45+
boxel-card-header-text-color=(getContrastColor @headerColor)
5546
}}
5647
...attributes
5748
>
5849
<div
5950
class='realm-icon-container'
60-
style={{cssVar
61-
boxel-realm-icon-background-color=(getContrastColor
62-
this.headerColor 'transparent'
63-
)
64-
boxel-realm-icon-border=(concat
65-
'1px solid '
66-
(getContrastColor this.headerColor 'rgba(0, 0, 0, 0.15)')
51+
style={{if
52+
@headerColor
53+
(cssVar
54+
boxel-realm-icon-background-color=(getContrastColor
55+
@headerColor 'transparent'
56+
)
57+
boxel-realm-icon-border-color=(getContrastColor
58+
@headerColor 'rgba(0, 0, 0, 0.15)'
59+
)
6760
)
6861
}}
6962
>
@@ -264,12 +257,14 @@ export default class CardHeader extends Component<Signature> {
264257
align-items: center;
265258
min-width: var(--boxel-card-header-icon-container-min-width);
266259
justify-content: left;
267-
--boxel-realm-icon-background-color: var(--boxel-light);
268-
--boxel-realm-icon-border-radius: 7px;
269-
}
270-
.is-editing .realm-icon-container {
271-
--boxel-realm-icon-background-color: var(--boxel-light);
272-
--boxel-realm-icon-border: 1px solid var(--boxel-light);
260+
--boxel-realm-icon-background-color: var(
261+
--realm-icon-background-color
262+
);
263+
--boxel-realm-icon-border-color: var(--realm-icon-border-color);
264+
--boxel-realm-icon-border-radius: var(
265+
--realm-icon-border-radius,
266+
7px
267+
);
273268
}
274269
275270
.realm-icon {

packages/boxel-ui/addon/src/components/card-header/usage.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default class CardHeaderUsage extends Component {
134134
/>
135135
<Args.String
136136
@name='headerColor'
137-
@description='background color of the header, defaults to boxel-light'
137+
@description='background color of the header'
138138
@value={{this.headerColor}}
139139
@onInput={{fn (mut this.headerColor)}}
140140
/>
@@ -195,15 +195,15 @@ export default class CardHeaderUsage extends Component {
195195
<Css.Basic
196196
@name='boxel-card-header-icon-container-min-width'
197197
@type='length'
198-
@description='minimum width of the icon container; useful to set matching boxel-card-header-actions-min-width to keep the title centered opverall'
198+
@description='minimum width of the icon container; useful to set matching boxel-card-header-actions-min-width to keep the title centered overall'
199199
@defaultValue={{this.cardHeaderIconContainerMinWidth.defaults}}
200200
@value={{this.cardHeaderIconContainerMinWidth.value}}
201201
@onInput={{this.cardHeaderIconContainerMinWidth.update}}
202202
/>
203203
<Css.Basic
204204
@name='boxel-card-header-actions-min-width'
205205
@type='length'
206-
@description='minimum width of the actions container; useful to set matching boxel-card-header-icon-container-min-width to keep the title centered opverall'
206+
@description='minimum width of the actions container; useful to set matching boxel-card-header-icon-container-min-width to keep the title centered overall'
207207
@defaultValue={{this.cardHeaderActionsMinWidth.defaults}}
208208
@value={{this.cardHeaderActionsMinWidth.value}}
209209
@onInput={{this.cardHeaderActionsMinWidth.update}}

packages/host/app/components/operator-mode/stack-item.gts

+15-3
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,14 @@ export default class OperatorModeStackItem extends Component<Signature> {
624624
boxel-card-header-actions-min-width=(if
625625
this.isBuried '50px' '95px'
626626
)
627-
realm-icon-background=(getContrastColor
627+
boxel-card-header-background-color=@item.headerColor
628+
boxel-card-header-text-color=(getContrastColor @item.headerColor)
629+
realm-icon-background-color=(getContrastColor
628630
@item.headerColor 'transparent'
629631
)
632+
realm-icon-border-color=(getContrastColor
633+
@item.headerColor 'transparent' 'rgba(0 0 0 / 15%)'
634+
)
630635
}}
631636
role={{if this.isBuried 'button' 'banner'}}
632637
{{on
@@ -654,7 +659,6 @@ export default class OperatorModeStackItem extends Component<Signature> {
654659
<CardHeader
655660
@cardTypeDisplayName={{this.headerTitle}}
656661
@cardTypeIcon={{cardTypeIcon @item.card}}
657-
@headerColor={{@item.headerColor}}
658662
@isSaving={{this.isSaving}}
659663
@isTopCard={{this.isTopCard}}
660664
@lastSavedMessage={{this.lastSavedMsg}}
@@ -671,9 +675,16 @@ export default class OperatorModeStackItem extends Component<Signature> {
671675
boxel-card-header-actions-min-width=(if
672676
this.isBuried '50px' '95px'
673677
)
674-
realm-icon-background=(getContrastColor
678+
boxel-card-header-background-color=@item.headerColor
679+
boxel-card-header-text-color=(getContrastColor
680+
@item.headerColor
681+
)
682+
realm-icon-background-color=(getContrastColor
675683
@item.headerColor 'transparent'
676684
)
685+
realm-icon-border-color=(getContrastColor
686+
@item.headerColor 'transparent' 'rgba(0 0 0 / 15%)'
687+
)
677688
}}
678689
role={{if this.isBuried 'button' 'banner'}}
679690
{{on
@@ -774,6 +785,7 @@ export default class OperatorModeStackItem extends Component<Signature> {
774785
775786
.item.buried {
776787
--stack-item-header-height: 2.5rem;
788+
--realm-icon-border-radius: 4px;
777789
}
778790
779791
.stack-item-card {

packages/host/tests/integration/components/operator-mode-test.gts

+59-8
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ module('Integration | operator-mode', function (hooks) {
328328

329329
class PublishingPacket extends CardDef {
330330
static displayName = 'Publishing Packet';
331+
static headerColor = '#6638ff'; // rgb(102, 56, 255);
331332
@field blogPost = linksTo(BlogPost);
332333
@field socialBlurb = contains(TextAreaField);
333334
}
@@ -351,6 +352,11 @@ module('Integration | operator-mode', function (hooks) {
351352
firstName: 'Alien',
352353
lastName: 'Bob',
353354
});
355+
let blogPost = new BlogPost({
356+
title: 'Outer Space Journey',
357+
body: 'Hello world',
358+
authorBio: author1,
359+
});
354360

355361
//Generate 11 person card to test recent card menu in card sheet
356362
let personCards: Map<String, any> = new Map<String, any>();
@@ -497,13 +503,13 @@ module('Integration | operator-mode', function (hooks) {
497503
firstName: 'Mark',
498504
lastName: 'Jackson',
499505
}),
500-
'BlogPost/1.json': new BlogPost({
501-
title: 'Outer Space Journey',
502-
body: 'Hello world',
503-
authorBio: author1,
504-
}),
506+
'BlogPost/1.json': blogPost,
505507
'BlogPost/2.json': new BlogPost({ title: 'Beginnings' }),
506508
'CardDef/1.json': new CardDef({ title: 'CardDef instance' }),
509+
'PublishingPacket/story.json': new PublishingPacket({
510+
title: 'Space Story',
511+
blogPost,
512+
}),
507513
'.realm.json': `{ "name": "${realmName}", "iconURL": "https://boxel-images.boxel.ai/icons/Letter-o.png" }`,
508514
...Object.fromEntries(personCards),
509515
},
@@ -2972,7 +2978,7 @@ module('Integration | operator-mode', function (hooks) {
29722978
assert
29732979
.dom(`[data-test-cards-grid-item="${testRealmURL}CardDef/1"]`)
29742980
.exists();
2975-
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 9 });
2981+
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 10 });
29762982
assert.dom(`[data-test-boxel-filter-list-button="Skill"]`).doesNotExist();
29772983

29782984
await click('[data-test-create-new-card-button]');
@@ -2992,7 +2998,7 @@ module('Integration | operator-mode', function (hooks) {
29922998
await click('[data-test-close-button]');
29932999
},
29943000
});
2995-
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 10 });
3001+
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 11 });
29963002
assert.dom(`[data-test-boxel-filter-list-button="Skill"]`).exists();
29973003

29983004
await click('[data-test-boxel-filter-list-button="Skill"]');
@@ -3008,7 +3014,7 @@ module('Integration | operator-mode', function (hooks) {
30083014
},
30093015
});
30103016

3011-
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 9 });
3017+
assert.dom(`[data-test-boxel-filter-list-button]`).exists({ count: 10 });
30123018
assert.dom(`[data-test-boxel-filter-list-button="Skill"]`).doesNotExist();
30133019
assert
30143020
.dom(`[data-test-boxel-filter-list-button="All Cards"]`)
@@ -3066,4 +3072,49 @@ module('Integration | operator-mode', function (hooks) {
30663072
.dom(`[data-test-stack-card-index="0"]`)
30673073
.doesNotHaveClass('opening-animation');
30683074
});
3075+
3076+
test('stack item with custom header color does not lose the color when opening other cards in the stack', async function (assert) {
3077+
const cardId = `${testRealmURL}PublishingPacket/story`;
3078+
const customStyle = {
3079+
backgroundColor: 'rgb(102, 56, 255)',
3080+
color: 'rgb(255, 255, 255)',
3081+
};
3082+
await setCardInOperatorModeState(cardId);
3083+
await renderComponent(
3084+
class TestDriver extends GlimmerComponent {
3085+
<template>
3086+
<OperatorMode @onClose={{noop}} />
3087+
<CardPrerender />
3088+
</template>
3089+
},
3090+
);
3091+
assert.dom(`[data-test-stack-card="${cardId}"]`).exists();
3092+
assert
3093+
.dom(`[data-stack-card="${cardId}"] [data-test-card-header]`)
3094+
.hasStyle(customStyle);
3095+
3096+
await click(`[data-test-card="${testRealmURL}BlogPost/1"]`);
3097+
assert.dom(`[data-test-stack-card="${testRealmURL}BlogPost/1"]`).exists();
3098+
assert
3099+
.dom(
3100+
`[data-stack-card="${testRealmURL}BlogPost/1"] [data-test-card-header]`,
3101+
)
3102+
.hasStyle({
3103+
backgroundColor: 'rgb(255, 255, 255)',
3104+
color: 'rgb(0, 0, 0)',
3105+
});
3106+
assert
3107+
.dom(`[data-stack-card="${cardId}"] [data-test-card-header]`)
3108+
.hasStyle(customStyle);
3109+
3110+
await click(
3111+
`[data-stack-card="${testRealmURL}BlogPost/1"] [data-test-close-button]`,
3112+
);
3113+
await waitFor(`[data-test-stack-card="${testRealmURL}BlogPost/1"]`, {
3114+
count: 0,
3115+
});
3116+
assert
3117+
.dom(`[data-stack-card="${cardId}"] [data-test-card-header]`)
3118+
.hasStyle(customStyle);
3119+
});
30693120
});

0 commit comments

Comments
 (0)