Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions packages/react/src/component-tests/IcDivider/IcDivider.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,38 @@ describe("IcDivider visual and a11y testing", () => {
testThreshold: setThresholdBasedOnEnv(DEFAULT_TEST_THRESHOLD + 0.087),
});
});

it("should stretch vertical dividers in a flex container without an explicit height", () => {
cy.viewport(700, 320);
mount(
<div
style={{
display: "flex",
gap: "var(--ic-space-lg)",
padding: "var(--ic-space-lg)",
}}
>
<div style={{ width: "160px", padding: "var(--ic-space-md)" }}>
<p>Intrinsic content gives this flex container its height.</p>
</div>
<IcDivider orientation="vertical" flexItem />
<IcDivider
orientation="vertical"
flexItem
label="Flex item"
labelPlacement="center"
/>
<div style={{ width: "160px", padding: "var(--ic-space-md)" }}>
<p>The dividers stretch without an explicit parent height.</p>
</div>
</div>
);
cy.checkHydrated(DIVIDER_SELECTOR);

cy.checkA11yWithWait();
cy.compareSnapshot({
name: "/flex-item",
testThreshold: setThresholdBasedOnEnv(DEFAULT_TEST_THRESHOLD + 0.02),
});
});
});
29 changes: 29 additions & 0 deletions packages/react/src/stories/ic-divider.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,35 @@ export const LabelPlacement = {
name: "Label placement",
};

export const FlexItem = {
render: () => (
<div
style={{
display: "flex",
gap: "var(--ic-space-lg)",
padding: "var(--ic-space-lg)",
}}
>
<div style={{ width: "10rem", padding: "var(--ic-space-md)" }}>
<p>Intrinsic content gives this flex container its height.</p>
</div>
<IcDivider orientation="vertical" flexItem />
<IcDivider
orientation="vertical"
flexItem
label="Flex item"
labelPlacement="center"
/>
<div style={{ width: "10rem", padding: "var(--ic-space-md)" }}>
<p>The vertical dividers stretch without an explicit parent height.</p>
</div>
</div>
),

name: "Flex item",
};


export const Playground = {
render: (args) => {
const backgroundColor =
Expand Down
8 changes: 8 additions & 0 deletions packages/web-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ export namespace Components {
* The line style of the divider.
*/
"borderStyle"?: IcDividerStyles;
/**
* If `true`, a vertical divider will stretch to the height of its flex container.
*/
"flexItem"?: boolean;
/**
* The label for the divider. The label placement will need to be set for the label to be displayed correctly.
*/
Expand Down Expand Up @@ -4794,6 +4798,10 @@ declare namespace LocalJSX {
* The line style of the divider.
*/
"borderStyle"?: IcDividerStyles;
/**
* If `true`, a vertical divider will stretch to the height of its flex container.
*/
"flexItem"?: boolean;
/**
* The label for the divider. The label placement will need to be set for the label to be displayed correctly.
*/
Expand Down
18 changes: 18 additions & 0 deletions packages/web-components/src/components/ic-divider/ic-divider.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ hr {
border: none;
}

:host(.ic-divider-vertical.ic-divider-flex-item) {
align-self: stretch;
height: auto;
}

:host(.ic-divider-vertical) div.vertical-divider {
display: flex;
height: inherit;
}

:host(.ic-divider-vertical.ic-divider-flex-item) div.vertical-divider {
flex-grow: 1;
height: auto;
}

:host(.ic-divider-vertical.ic-divider-label-bottom)::before,
:host(.ic-divider-vertical.ic-divider-label-center)::before,
:host(.ic-divider-vertical.ic-divider-label-top)::after,
Expand All @@ -82,6 +92,14 @@ hr {
height: 100%;
}

:host(.ic-divider-vertical.ic-divider-flex-item.ic-divider-label-bottom)::before,
:host(.ic-divider-vertical.ic-divider-flex-item.ic-divider-label-center)::before,
:host(.ic-divider-vertical.ic-divider-flex-item.ic-divider-label-top)::after,
:host(.ic-divider-vertical.ic-divider-flex-item.ic-divider-label-center)::after {
flex-grow: 1;
height: auto;
}

/* Theme */
hr,
:host(.ic-divider-horizontal.ic-divider-label-right)::before,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,30 @@ export const LabelPlacement = {
name: "Label placement",
};

export const FlexItem = {
render: () => html`
<div
style="display: flex; gap: var(--ic-space-lg); padding: var(--ic-space-lg);"
>
<div style="width: 10rem; padding: var(--ic-space-md);">
<p>Intrinsic content gives this flex container its height.</p>
</div>
<ic-divider orientation="vertical" flex-item="true"></ic-divider>
<ic-divider
orientation="vertical"
flex-item="true"
label="Flex item"
label-placement="center"
></ic-divider>
<div style="width: 10rem; padding: var(--ic-space-md);">
<p>The vertical dividers stretch without an explicit parent height.</p>
</div>
</div>
`,

name: "Flex item",
};

export const Playground = {
render: (args) => {
const backgroundColor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export class Divider {
*/
@Prop() borderStyle?: IcDividerStyles = "solid";

/**
* If `true`, a vertical divider will stretch to the height of its flex container.
*/
@Prop() flexItem?: boolean = false;

/**
* The label for the divider. The label placement will need to be set for the label to be displayed correctly.
*/
Expand Down Expand Up @@ -117,6 +122,7 @@ export class Divider {
render() {
const {
borderStyle,
flexItem,
label,
labelPlacement,
monochrome,
Expand Down Expand Up @@ -184,6 +190,7 @@ export class Divider {
[`ic-divider-${orientation}`]: true,
[`ic-divider-${weight}`]: true,
[`ic-divider-${borderStyle}`]: true,
[`ic-divider-flex-item`]: !!flexItem,
[`ic-divider-label-${labelPlacement}`]:
slotHasContent(this.el, "label") || !isEmptyString(label),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| Property | Attribute | Description | Type | Default |
| ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -------------- |
| `borderStyle` | `border-style` | The line style of the divider. | `"dashed" \| "solid" \| undefined` | `"solid"` |
| `flexItem` | `flex-item` | If `true`, a vertical divider will stretch to the height of its flex container. | `boolean \| undefined` | `false` |
| `label` | `label` | The label for the divider. The label placement will need to be set for the label to be displayed correctly. | `string \| undefined` | `undefined` |
| `labelPlacement` | `label-placement` | The position the label is placed on the divider. `Left` and `right` placement is only applicable when orientation is set to `horizontal`. `Top` and `bottom` placement is only applicable when orientation is set to `vertical`. `Center` placement is applicable for both orientations. | `"bottom" \| "center" \| "left" \| "right" \| "top" \| undefined` | `"center"` |
| `monochrome` | `monochrome` | If `true`, the divider will be displayed in a grey colour. | `boolean \| undefined` | `false` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ describe("ic-divider", () => {
expect(page.root).toMatchSnapshot();
});

it("should apply the flex item class when flex-item is true", async () => {
const page = await newSpecPage({
components: [Divider],
html: `<ic-divider orientation="vertical" flex-item="true"></ic-divider>`,
});

expect(page.root).toHaveClass("ic-divider-flex-item");
});

it("should render with a slotted label", async () => {
const page = await newSpecPage({
components: [Divider],
Expand Down