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 color and label prop to swirl-separator #885

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/orange-cats-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@getflip/swirl-components": minor
"@getflip/swirl-components-angular": minor
"@getflip/swirl-components-react": minor
---

Add color and label prop to swirl-separator
12 changes: 8 additions & 4 deletions packages/swirl-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { SwirlRadioState, SwirlRadioVariant } from "./components/swirl-radio/swi
import { SwirlStackSpacing } from "./components/swirl-stack/swirl-stack";
import { SwirlResourceListItemLabelWeight } from "./components/swirl-resource-list-item/swirl-resource-list-item";
import { SwirlSearchVariant } from "./components/swirl-search/swirl-search";
import { SwirlSeparatorBorderColor, SwirlSeparatorOrientation, SwirlSeparatorSpacing } from "./components/swirl-separator/swirl-separator";
import { SwirlSeparatorColor, SwirlSeparatorOrientation, SwirlSeparatorSpacing } from "./components/swirl-separator/swirl-separator";
import { SwirlLabelColor } from "./components/swirl-shell-navigation-item/swirl-shell-navigation-item";
import { SwirlSkeletonBoxBorderRadius } from "./components/swirl-skeleton-box/swirl-skeleton-box";
import { SwirlSkeletonTextSize } from "./components/swirl-skeleton-text/swirl-skeleton-text";
Expand Down Expand Up @@ -117,7 +117,7 @@ export { SwirlRadioState, SwirlRadioVariant } from "./components/swirl-radio/swi
export { SwirlStackSpacing } from "./components/swirl-stack/swirl-stack";
export { SwirlResourceListItemLabelWeight } from "./components/swirl-resource-list-item/swirl-resource-list-item";
export { SwirlSearchVariant } from "./components/swirl-search/swirl-search";
export { SwirlSeparatorBorderColor, SwirlSeparatorOrientation, SwirlSeparatorSpacing } from "./components/swirl-separator/swirl-separator";
export { SwirlSeparatorColor, SwirlSeparatorOrientation, SwirlSeparatorSpacing } from "./components/swirl-separator/swirl-separator";
export { SwirlLabelColor } from "./components/swirl-shell-navigation-item/swirl-shell-navigation-item";
export { SwirlSkeletonBoxBorderRadius } from "./components/swirl-skeleton-box/swirl-skeleton-box";
export { SwirlSkeletonTextSize } from "./components/swirl-skeleton-text/swirl-skeleton-text";
Expand Down Expand Up @@ -1848,7 +1848,9 @@ export namespace Components {
"withSearch"?: boolean;
}
interface SwirlSeparator {
"borderColor"?: SwirlSeparatorBorderColor;
"borderColor"?: SwirlSeparatorColor;
"color"?: SwirlSeparatorColor;
"label"?: string;
"orientation"?: SwirlSeparatorOrientation;
"spacing"?: SwirlSeparatorSpacing;
}
Expand Down Expand Up @@ -7381,7 +7383,9 @@ declare namespace LocalJSX {
"withSearch"?: boolean;
}
interface SwirlSeparator {
"borderColor"?: SwirlSeparatorBorderColor;
"borderColor"?: SwirlSeparatorColor;
"color"?: SwirlSeparatorColor;
"label"?: string;
"orientation"?: SwirlSeparatorOrientation;
"spacing"?: SwirlSeparatorSpacing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
display: flex;
width: 100%;
align-items: center;
gap: var(--s-space-8);

& * {
box-sizing: border-box;
Expand All @@ -10,6 +11,7 @@
&(.separator--orientation-vertical) {
display: inline-flex;
width: auto;
flex-direction: column;

& .separator__line {
width: var(--s-border-width-default);
Expand All @@ -18,16 +20,24 @@
}
}

&(.separator--border-color-strong) {
&(.separator--color-strong) {
& .separator__line {
background-color: var(--s-border-strong);
}

& .separator__label {
color: var(--s-text-subdued);
}
}

&(.separator--border-color-highlight) {
&(.separator--color-highlight) {
& .separator__line {
background-color: var(--s-border-highlight);
}

& .separator__label {
color: var(--s-text-highlight);
}
}
}

Expand All @@ -37,3 +47,10 @@
height: var(--s-border-width-default);
background-color: var(--s-border-default);
}

.separator__label {
flex-shrink: 0;
width: fit-content;
font-size: var(--s-font-size-sm);
color: var(--s-text-disabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,58 @@ describe("swirl-separator", () => {
});

expect(page.root).toEqualHtml(`
<swirl-separator aria-orientation="horizontal" class="separator separator--border-color-default separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<swirl-separator aria-orientation="horizontal" class="separator separator--color-default separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<mock:shadow-root>
<span class="separator__line"></span>
</mock:shadow-root>
</swirl-separator>
`);
});

it("renders with strong border color", async () => {
it("renders with strong color", async () => {
const page = await newSpecPage({
components: [SwirlSeparator],
html: `<swirl-separator border-color="strong"></swirl-separator>`,
html: `<swirl-separator color="strong"></swirl-separator>`,
});

expect(page.root).toEqualHtml(`
<swirl-separator aria-orientation="horizontal" border-color="strong" class="separator separator--border-color-strong separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<swirl-separator aria-orientation="horizontal" color="strong" class="separator separator--color-strong separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<mock:shadow-root>
<span class="separator__line"></span>
</mock:shadow-root>
</swirl-separator>
`);
});

it("renders with highlight color", async () => {
const page = await newSpecPage({
components: [SwirlSeparator],
html: `<swirl-separator color="highlight"></swirl-separator>`,
});

expect(page.root).toEqualHtml(`
<swirl-separator aria-orientation="horizontal" color="highlight" class="separator separator--color-highlight separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<mock:shadow-root>
<span class="separator__line"></span>
</mock:shadow-root>
</swirl-separator>
`);
});

it("renders the label", async () => {
const page = await newSpecPage({
components: [SwirlSeparator],
html: `<swirl-separator label="Label"></swirl-separator>`,
});

expect(page.root).toEqualHtml(`
<swirl-separator aria-orientation="horizontal" label="Label" class="separator separator--color-default separator--orientation-horizontal" role="separator" style="padding-top: var(--s-space-8); padding-bottom: var(--s-space-8);">
<mock:shadow-root>
<span class="separator__line"></span>
<span class="separator__label">Label</span>
<span class="separator__line"></span>
</mock:shadow-root>
</swirl-separator>
`);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, h, Host, Prop } from "@stencil/core";
import { Component, Fragment, h, Host, Prop } from "@stencil/core";
import classnames from "classnames";

export type SwirlSeparatorBorderColor = "default" | "strong" | "highlight";
export type SwirlSeparatorColor = "default" | "strong" | "highlight";
export type SwirlSeparatorOrientation = "horizontal" | "vertical";

export type SwirlSeparatorSpacing =
Expand All @@ -20,10 +20,25 @@ export type SwirlSeparatorSpacing =
tag: "swirl-separator",
})
export class SwirlSeparator {
@Prop() borderColor?: SwirlSeparatorBorderColor = "default";
@Prop() borderColor?: SwirlSeparatorColor = "default";
@Prop({ mutable: true }) color?: SwirlSeparatorColor = "default";
@Prop() label?: string;
@Prop() orientation?: SwirlSeparatorOrientation = "horizontal";
nunofaria11 marked this conversation as resolved.
Show resolved Hide resolved
@Prop() spacing?: SwirlSeparatorSpacing = "8";

componentWillLoad() {
this.forceColor();
}

private forceColor() {
if (this.borderColor !== "default") {
console.warn(
'[Swirl] The "borderColor" prop of swirl-separator is deprecated and will be removed with the next major release. Please use the "color" prop to achieve the same result.'
);
this.color = this.borderColor;
}
}

render() {
const styles =
this.orientation === "horizontal"
Expand All @@ -38,7 +53,7 @@ export class SwirlSeparator {

const className = classnames(
"separator",
`separator--border-color-${this.borderColor}`,
`separator--color-${this.color}`,
`separator--orientation-${this.orientation}`
);

Expand All @@ -50,6 +65,12 @@ export class SwirlSeparator {
style={styles}
>
<span class="separator__line"></span>
{this.label && (
<Fragment>
<span class="separator__label">{this.label}</span>
<span class="separator__line"></span>
</Fragment>
)}
</Host>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("swirl-shell-layout", () => {
});

expect(page.root.innerHTML).toMatchInlineSnapshot(
`"<!----> <div slot=\\"header-tools\\" hidden=\\"\\">Tools</div> <div slot=\\"sidebar-header\\" hidden=\\"\\">Sidebar header</div> <div class=\\"shell-layout\\"><header class=\\"shell-layout__header\\" data-tauri-drag-region=\\"true\\"><button class=\\"shell-layout__skip-link\\" type=\\"button\\">Skip to main content</button><div class=\\"shell-layout__header-left\\"><swirl-tooltip content=\\"Collapse navigation\\" delay=\\"100\\" position=\\"right\\"><button class=\\"shell-layout__header-tool\\" type=\\"button\\"><swirl-icon-dock-left-collapse size=\\"20\\"></swirl-icon-dock-left-collapse><swirl-visually-hidden>Collapse navigation</swirl-visually-hidden></button></swirl-tooltip><a class=\\"shell-layout__header-tool\\" href=\\"javascript:history.back()\\"><swirl-icon-arrow-back size=\\"20\\"></swirl-icon-arrow-back><swirl-visually-hidden>Navigate back</swirl-visually-hidden></a><a class=\\"shell-layout__header-tool\\" href=\\"javascript:history.forward()\\"><swirl-icon-arrow-forward size=\\"20\\"></swirl-icon-arrow-forward><swirl-visually-hidden>Navigate forward</swirl-visually-hidden></a> </div><div class=\\"shell-layout__logo\\"> <div slot=\\"logo\\">Logo</div></div><div class=\\"shell-layout__header-right\\"> <button class=\\"shell-layout__header-tool shell-layout__sidebar-toggle\\" type=\\"button\\"><swirl-icon glyph=\\"notifications\\" size=\\"20\\"></swirl-icon><swirl-visually-hidden>Toggle sidebar</swirl-visually-hidden></button> </div></header><div class=\\"shell-layout__mobile-nav-backdrop\\"></div><nav aria-labelledby=\\"main-navigation-label\\" class=\\"shell-layout__nav\\"><div class=\\"shell-layout__mobile-header\\"> <div slot=\\"mobile-logo\\">Mobile logo</div><div class=\\"shell-layout__mobile-header-tools\\"> <button class=\\"shell-layout__header-tool\\" type=\\"button\\"><swirl-icon-double-arrow-left size=\\"20\\"></swirl-icon-double-arrow-left><swirl-visually-hidden>Close navigation</swirl-visually-hidden></button></div></div><div class=\\"shell-layout__nav-body\\"><swirl-visually-hidden><span id=\\"main-navigation-label\\">Main</span></swirl-visually-hidden> <div slot=\\"nav\\">nav</div><div class=\\"shell-layout__secondary-nav\\"><swirl-separator bordercolor=\\"strong\\" spacing=\\"16\\"></swirl-separator><swirl-box paddingblockend=\\"16\\"><swirl-stack justify=\\"space-between\\" orientation=\\"horizontal\\"><swirl-button icon=\\"<swirl-icon-expand-less></swirl-icon-expand-less>\\" label=\\"Show less\\" variant=\\"plain\\"></swirl-button><swirl-button icon=\\"<swirl-icon-hamburger-menu></swirl-icon-hamburger-menu>\\" iconposition=\\"end\\" label=\\"List\\" variant=\\"plain\\"></swirl-button></swirl-stack></swirl-box><div class=\\"shell-layout__secondary-nav-items\\"></div></div></div></nav><main class=\\"shell-layout__main\\" id=\\"main-content\\"> <div>Main</div> </main><aside class=\\"shell-layout__sidebar\\" inert=\\"\\"><div class=\\"shell-layout__sidebar-body\\"><div class=\\"shell-layout__sidebar-app-bar\\"></div><div class=\\"shell-layout__sidebar-content\\"> <div slot=\\"sidebar\\">Sidebar</div></div></div></aside></div>"`
`"<!----> <div slot=\\"header-tools\\" hidden=\\"\\">Tools</div> <div slot=\\"sidebar-header\\" hidden=\\"\\">Sidebar header</div> <div class=\\"shell-layout\\"><header class=\\"shell-layout__header\\" data-tauri-drag-region=\\"true\\"><button class=\\"shell-layout__skip-link\\" type=\\"button\\">Skip to main content</button><div class=\\"shell-layout__header-left\\"><swirl-tooltip content=\\"Collapse navigation\\" delay=\\"100\\" position=\\"right\\"><button class=\\"shell-layout__header-tool\\" type=\\"button\\"><swirl-icon-dock-left-collapse size=\\"20\\"></swirl-icon-dock-left-collapse><swirl-visually-hidden>Collapse navigation</swirl-visually-hidden></button></swirl-tooltip><a class=\\"shell-layout__header-tool\\" href=\\"javascript:history.back()\\"><swirl-icon-arrow-back size=\\"20\\"></swirl-icon-arrow-back><swirl-visually-hidden>Navigate back</swirl-visually-hidden></a><a class=\\"shell-layout__header-tool\\" href=\\"javascript:history.forward()\\"><swirl-icon-arrow-forward size=\\"20\\"></swirl-icon-arrow-forward><swirl-visually-hidden>Navigate forward</swirl-visually-hidden></a> </div><div class=\\"shell-layout__logo\\"> <div slot=\\"logo\\">Logo</div></div><div class=\\"shell-layout__header-right\\"> <button class=\\"shell-layout__header-tool shell-layout__sidebar-toggle\\" type=\\"button\\"><swirl-icon glyph=\\"notifications\\" size=\\"20\\"></swirl-icon><swirl-visually-hidden>Toggle sidebar</swirl-visually-hidden></button> </div></header><div class=\\"shell-layout__mobile-nav-backdrop\\"></div><nav aria-labelledby=\\"main-navigation-label\\" class=\\"shell-layout__nav\\"><div class=\\"shell-layout__mobile-header\\"> <div slot=\\"mobile-logo\\">Mobile logo</div><div class=\\"shell-layout__mobile-header-tools\\"> <button class=\\"shell-layout__header-tool\\" type=\\"button\\"><swirl-icon-double-arrow-left size=\\"20\\"></swirl-icon-double-arrow-left><swirl-visually-hidden>Close navigation</swirl-visually-hidden></button></div></div><div class=\\"shell-layout__nav-body\\"><swirl-visually-hidden><span id=\\"main-navigation-label\\">Main</span></swirl-visually-hidden> <div slot=\\"nav\\">nav</div><div class=\\"shell-layout__secondary-nav\\"><swirl-separator color=\\"strong\\" spacing=\\"16\\"></swirl-separator><swirl-box paddingblockend=\\"16\\"><swirl-stack justify=\\"space-between\\" orientation=\\"horizontal\\"><swirl-button icon=\\"<swirl-icon-expand-less></swirl-icon-expand-less>\\" label=\\"Show less\\" variant=\\"plain\\"></swirl-button><swirl-button icon=\\"<swirl-icon-hamburger-menu></swirl-icon-hamburger-menu>\\" iconposition=\\"end\\" label=\\"List\\" variant=\\"plain\\"></swirl-button></swirl-stack></swirl-box><div class=\\"shell-layout__secondary-nav-items\\"></div></div></div></nav><main class=\\"shell-layout__main\\" id=\\"main-content\\"> <div>Main</div> </main><aside class=\\"shell-layout__sidebar\\" inert=\\"\\"><div class=\\"shell-layout__sidebar-body\\"><div class=\\"shell-layout__sidebar-app-bar\\"></div><div class=\\"shell-layout__sidebar-content\\"> <div slot=\\"sidebar\\">Sidebar</div></div></div></aside></div>"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class SwirlShellLayout {
<slot name="nav" onSlotchange={this.collectNavItems}></slot>
<div class="shell-layout__secondary-nav">
<swirl-separator
borderColor="strong"
color="strong"
spacing="16"
></swirl-separator>
{this.enableSecondaryNavGridLayout && (
Expand Down
19 changes: 19 additions & 0 deletions packages/swirl-components/vscode-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15446,6 +15446,25 @@
}
]
},
{
"name": "color",
"description": "",
"values": [
{
"name": "default"
},
{
"name": "highlight"
},
{
"name": "strong"
}
]
},
{
"name": "label",
"description": ""
},
{
"name": "orientation",
"description": "",
Expand Down
Loading