Skip to content

Commit bff9a3e

Browse files
feat: separator
1 parent f555d13 commit bff9a3e

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { PrimitiveProps } from '~/primitive/index.ts'
2+
3+
export interface SeparatorProps extends PrimitiveProps {
4+
/**
5+
* Either `vertical` or `horizontal`. Defaults to `horizontal`.
6+
*/
7+
orientation?: 'vertical' | 'horizontal'
8+
/**
9+
* Whether or not the component is purely decorative. When true, accessibility-related attributes
10+
* are updated so that that the rendered element is removed from the accessibility tree.
11+
*/
12+
decorative?: boolean
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script setup lang="ts">
2+
import type { SeparatorProps } from './Separator.ts'
3+
import { Primitive } from '~/primitive/index.ts'
4+
5+
defineOptions({
6+
name: 'Separator',
7+
})
8+
9+
withDefaults(defineProps<SeparatorProps>(), {
10+
orientation: 'horizontal',
11+
})
12+
</script>
13+
14+
<template>
15+
<Primitive
16+
:as="as"
17+
:as-child="asChild"
18+
:data-orientation="orientation"
19+
v-bind="{
20+
...(
21+
decorative ? {
22+
role: 'none',
23+
} : {
24+
'aria-orientation': orientation === 'vertical' ? orientation : undefined,
25+
'role': 'separator',
26+
}
27+
),
28+
}"
29+
>
30+
<slot />
31+
</Primitive>
32+
</template>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Separator } from './Separator.vue'
2+
export type{ SeparatorProps } from './Separator.ts'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Separator } from '../index.ts'
2+
import './styles.css'
3+
4+
export default { title: 'Components/Separator' }
5+
6+
export function Styled() {
7+
return (
8+
<>
9+
<h1>Horizontal</h1>
10+
<p>The following separator is horizontal and has semantic meaning.</p>
11+
<Separator class="separator_root" orientation="horizontal" />
12+
<p>
13+
The following separator is horizontal and is purely decorative. Assistive technology will
14+
ignore this element.
15+
</p>
16+
<Separator class="separator_root" orientation="horizontal" decorative />
17+
18+
<h1>Vertical</h1>
19+
<div style={{ display: 'flex', alignItems: 'center' }}>
20+
<p>The following separator is vertical and has semantic meaning.</p>
21+
<Separator class="separator_root" orientation="vertical" />
22+
<p>
23+
The following separator is vertical and is purely decorative. Assistive technology will
24+
ignore this element.
25+
</p>
26+
<Separator class="separator_root" orientation="vertical" decorative />
27+
</div>
28+
</>
29+
)
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.separator_root {
2+
border: none;
3+
background-color: red;
4+
5+
&[data-orientation="horizontal"] {
6+
height: 1px;
7+
width: 100%;
8+
margin: 20px 0;
9+
}
10+
11+
&[data-orientation="vertical"] {
12+
height: 100px;
13+
width: 1px;
14+
margin: 0 20px;
15+
}
16+
}

0 commit comments

Comments
 (0)