Skip to content

Commit

Permalink
fix(tags): support distant sibling selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Aug 29, 2020
1 parent 4833a59 commit a8dcf7f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/split-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"lit-html": "^1.0.0"
},
"devDependencies": {
"@spectrum-css/splitbutton": "^3.0.0-beta.3"
"@spectrum-css/splitbutton": "^3.0.0-beta.3",
"@spectrum-web-components/menu": "^0.3.0"
},
"dependencies": {
"@spectrum-web-components/button": "^0.8.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/split-button/stories/split-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { TemplateResult } from 'lit-html';
import { html, action } from '@open-wc/demoing-storybook';

import '../sp-split-button.js';
import '@spectrum-web-components/menu/sp-menu.js';
import '@spectrum-web-components/menu/sp-menu-item.js';

export default {
title: 'Split Button',
Expand Down Expand Up @@ -117,7 +119,7 @@ moreCta.story = {
export const moreCtaOpen = (options = {}): TemplateResult => {
return html`
<div>
<sp-split-button open>
<sp-split-button type="more" open>
${menu(options)}
</sp-split-button>
</div>
Expand Down
26 changes: 24 additions & 2 deletions packages/tags/src/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export class Tag extends LitElement {
@property({ type: Boolean, reflect: true })
public disabled = false;

private get hasIcon(): boolean {
return !!this.querySelector('[slot="icon"]');
}

private get hasAvatar(): boolean {
return !!this.querySelector('[slot="avatar"]');
}

constructor() {
super();
this.addEventListener('focusin', this.handleFocusin);
Expand Down Expand Up @@ -77,9 +85,23 @@ export class Tag extends LitElement {
}

protected render(): TemplateResult {
const slots = [];
if (this.hasAvatar) {
slots.push(
html`
<slot name="avatar"></slot>
`
);
}
if (this.hasIcon) {
slots.push(
html`
<slot name="icon"></slot>
`
);
}
return html`
<slot name="avatar"></slot>
<slot name="icon"></slot>
${slots}
<span class="label"><slot></slot></span>
${this.deletable
? html`
Expand Down
15 changes: 15 additions & 0 deletions packages/tags/src/spectrum-tag.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ THIS FILE IS MACHINE GENERATED. DO NOT EDIT */
)
);
}
:host > slot[name='avatar'] ~ .label,
:host > slot[name='icon'] ~ .label {
/* .spectrum-Tags-item>.spectrum-Avatar~.spectrum-Tags-itemLabel,
* .spectrum-Tags-item>.spectrum-Icon~.spectrum-Tags-itemLabel */
margin-right: calc(
var(
--spectrum-tag-avatar-padding-x,
var(--spectrum-global-dimension-size-100)
) -
var(
--spectrum-tag-padding-x,
var(--spectrum-global-dimension-size-125)
)
);
}
.clear-button {
/* .spectrum-Tags-item .spectrum-ClearButton */
margin-right: calc(
Expand Down
3 changes: 2 additions & 1 deletion scripts/process-spectrum-postcss-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ class SpectrumProcessor {
if (!slot) return;
const isLastNode = index === result.length - 1;
const isSiblingSelector =
!isLastNode && node.next().value === '+';
!isLastNode &&
(node.next().value === '+' || node.next().value === '~');

if (isSiblingSelector && !isLastNode) {
// If a sibling selector is used, and the slot is not the last
Expand Down
6 changes: 3 additions & 3 deletions test/visual/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ module.exports = [
'split-button--cta',
'split-button--primary',
'split-button--primary',
'more-button--cta',
'more-button--primary',
'more-button--primary',
'split-button--more-cta',
'split-button--more-primary',
'split-button--more-primary',
'statuslight--all-variants',
'statuslight--disabled-true',
'switch--default',
Expand Down
2 changes: 1 addition & 1 deletion test/visual/visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
const config = createConfig({
port: 4444,
nodeResolve: true,
appIndex: 'index.hml',
appIndex: 'index.html',
rootDir: path.resolve(
process.cwd(),
'documentation',
Expand Down

0 comments on commit a8dcf7f

Please sign in to comment.