-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1393 from hashicorp/alex-ju/add-separator-component
Add `Separator` component
- Loading branch information
Showing
24 changed files
with
279 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hashicorp/design-system-components": minor | ||
--- | ||
|
||
Add `Separator` component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
}} | ||
<hr class={{this.classNames}} ...attributes /> |
47 changes: 47 additions & 0 deletions
47
packages/components/addon/components/hds/separator/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export const DEFAULT_SPACING = '24'; | ||
export const SPACING = ['24', '0']; | ||
|
||
export default class HdsSeparatorIndexComponent extends Component { | ||
/** | ||
* Sets the margin for the separator | ||
* Accepted values: 24, 0 | ||
* | ||
* @param spacing | ||
* @type {string} | ||
* @default 'default' | ||
*/ | ||
get spacing() { | ||
let { spacing = DEFAULT_SPACING } = this.args; | ||
|
||
assert( | ||
`@spacing for "Hds::Separator" must be one of the following: ${SPACING.join( | ||
', ' | ||
)}; received: ${spacing}`, | ||
SPACING.includes(spacing) | ||
); | ||
|
||
return spacing; | ||
} | ||
|
||
/** | ||
* Get the class names to apply to the component. | ||
* @method classNames | ||
* @return {string} The "class" attribute to apply to the component. | ||
*/ | ||
get classNames() { | ||
let classes = ['hds-separator']; | ||
|
||
// add a class based on the @spacing argument | ||
classes.push(`hds-separator--spacing-${this.spacing}`); | ||
|
||
return classes.join(' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
export { default } from '@hashicorp/design-system-components/components/hds/separator/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
// | ||
// SEPARATOR | ||
// | ||
|
||
.hds-separator { | ||
border: none; | ||
border-top: 1px solid var(--token-color-border-primary); | ||
} | ||
|
||
.hds-separator--spacing-24 { | ||
margin: 24px 0; | ||
} | ||
|
||
.hds-separator--spacing-0 { | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/components/tests/dummy/app/routes/components/separator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import Route from '@ember/routing/route'; | ||
|
||
export default class ComponentsSeparatorRoute extends Route {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/components/tests/dummy/app/styles/showcase-pages/separator.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
// SEPARATOR | ||
|
||
body.components-separator { | ||
.shw-component-separator-container { | ||
display: grid; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/components/tests/dummy/app/templates/components/separator.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
}} | ||
|
||
{{page-title "Separator Component"}} | ||
|
||
<Shw::Text::H1>Separator</Shw::Text::H1> | ||
|
||
<section data-test-percy> | ||
<Shw::Flex @direction="column" as |SF|> | ||
<SF.Item @label="Default (24px)"> | ||
<Shw::Outliner class="shw-component-separator-container"> | ||
<Hds::Separator /> | ||
</Shw::Outliner> | ||
</SF.Item> | ||
<SF.Item @label="No spacing (0px)"> | ||
<Shw::Outliner class="shw-component-separator-container"> | ||
<Hds::Separator @spacing="0" /> | ||
</Shw::Outliner> | ||
</SF.Item> | ||
</Shw::Flex> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/components/tests/integration/components/hds/separator/index-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, resetOnerror, setupOnerror } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Component | hds/separator/index', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.afterEach(() => { | ||
resetOnerror(); | ||
}); | ||
|
||
test('it should render the component with a CSS class that matches the component name', async function (assert) { | ||
await render(hbs`<Hds::Separator id="test-separator" />`); | ||
assert.dom('#test-separator').hasClass('hds-separator'); | ||
}); | ||
|
||
// SPACING | ||
|
||
test('it should render the component with CSS classes that reflect the default vaules if no arguments provided', async function (assert) { | ||
await render(hbs`<Hds::Separator id="test-separator" />`); | ||
assert.dom('#test-separator').hasClass('hds-separator--spacing-24'); | ||
}); | ||
|
||
test('it should render the component with CSS classes that reflect the arguments provided', async function (assert) { | ||
await render(hbs`<Hds::Separator @spacing="0" id="test-separator" />`); | ||
assert.dom('#test-separator').hasClass('hds-separator--spacing-0'); | ||
}); | ||
|
||
// ASSERTIONS | ||
|
||
test('it should throw an assertion if an incorrect value for @spacing is provided', async function (assert) { | ||
const errorMessage = | ||
'@spacing for "Hds::Separator" must be one of the following: 24, 0; received: foo'; | ||
assert.expect(2); | ||
setupOnerror(function (error) { | ||
assert.strictEqual(error.message, `Assertion Failed: ${errorMessage}`); | ||
}); | ||
await render(hbs`<Hds::Separator @spacing="foo" id="test-separator" />`); | ||
assert.throws(function () { | ||
throw new Error(errorMessage); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Separator | ||
description: Creates visual breaks between different sections of content | ||
caption: Creates visual breaks between different sections of content | ||
status: released | ||
links: | ||
figma: https://www.figma.com/file/9QeyvUQ8kuyIity6knrznO/Separator-Component?node-id=36433-70314&t=PXCxiaccZSis4g9x-4 | ||
github: https://github.com/hashicorp/design-system/tree/main/packages/components/addon/components/hds/separator | ||
previewImage: assets/illustrations/components/separator.jpg | ||
navigation: | ||
keywords: ['horizontal', 'rule', 'line' , 'hr', 'section', 'divider', 'break'] | ||
--- | ||
|
||
<section data-tab="Guidelines"> | ||
@include "partials/guidelines/overview.md" | ||
@include "partials/guidelines/guidelines.md" | ||
</section> | ||
|
||
<section data-tab="Code"> | ||
@include "partials/code/how-to-use.md" | ||
@include "partials/code/component-api.md" | ||
<!-- @include "partials/code/showcase.md" --> | ||
</section> | ||
|
||
<section data-tab="Accessibility"> | ||
@include "partials/accessibility/accessibility.md" | ||
</section> |
9 changes: 9 additions & 0 deletions
9
website/docs/components/separator/partials/accessibility/accessibility.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Conformance rating | ||
|
||
<Doc::Badge @type="success">Conformant</Doc::Badge> | ||
|
||
When used as recommended, there should not be any WCAG conformance issues with this component. | ||
|
||
--- | ||
|
||
<Doc::A11ySupport /> |
8 changes: 8 additions & 0 deletions
8
website/docs/components/separator/partials/code/component-api.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Component API | ||
|
||
<Doc::ComponentApi as |C|> | ||
<C.Property @name="spacing" @type="string" @values={{array "0" "24" }} @default="24"/> | ||
<C.Property @name="...attributes"> | ||
This component supports use of [`...attributes`](https://guides.emberjs.com/release/in-depth-topics/patterns-for-components/#toc_attribute-ordering). | ||
</C.Property> | ||
</Doc::ComponentApi> |
15 changes: 15 additions & 0 deletions
15
website/docs/components/separator/partials/code/how-to-use.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## How to use this component | ||
|
||
The Separator renders a thematic break element (also known as horizontal rule, or `<hr/>` element) with equal top and bottom margins to create space between sections. | ||
|
||
```handlebars | ||
<Hds::Separator/> | ||
``` | ||
|
||
### Spacing | ||
|
||
The default spacing value is `24` pixels. If you need to use the Separator without margins set `@spacing` to `0`. | ||
|
||
```handlebars | ||
<Hds::Separator @spacing="0"/> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Showcase | ||
|
||
<!-- Leave it as is, we don't expose the component showcase for now. --> |
27 changes: 27 additions & 0 deletions
27
website/docs/components/separator/partials/guidelines/guidelines.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
## Placement | ||
|
||
Use separators to distinguish between sections on a page visually. Use them sparingly and purposefully to avoid cluttering the UI and distracting users from the main content. | ||
|
||
!!! Do | ||
|
||
Use to create a clear break between paragraphs, blocks, or sections. | ||
|
||
![Example of the separator component used correctly between content sections] (/assets/components/separator/separator-do.png =275x*) | ||
|
||
!!! | ||
|
||
!!! Dont | ||
|
||
Don’t use to separate headings and body text. Instead, emphasize hierarchy by using the proper [Display font style](https://helios.hashicorp.design/foundations/typography?tab=code#font-styles). | ||
|
||
![Example of the separator component used improperly, causing clutter and disrupting content flow."](/assets/components/separator/separator-dont.png =600x*) | ||
|
||
!!! | ||
|
||
## Spacing | ||
|
||
We recommend using meaningful spacing between content elements, allowing users to scan and understand information quickly. | ||
|
||
- Use the `0px` spacing option for a tightly integrated layout without any visible gaps between elements. | ||
- Use the `24px` spacing option to visually distinguish between different sections, making it simpler for users to navigate and understand the content. |
Empty file.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
084bdeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hds-showcase – ./packages/components
hds-showcase-hashicorp.vercel.app
hds-showcase.vercel.app
hds-showcase-git-main-hashicorp.vercel.app
084bdeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hds-website – ./website
hds-website-hashicorp.vercel.app
hds-website.vercel.app
flight-hashicorp.vercel.app
hds-website-git-main-hashicorp.vercel.app
design-system-components-hashicorp.vercel.app
helios.hashicorp.design