diff --git a/.changeset/clean-dividers-sing.md b/.changeset/clean-dividers-sing.md
new file mode 100644
index 000000000..9e4c663cf
--- /dev/null
+++ b/.changeset/clean-dividers-sing.md
@@ -0,0 +1,5 @@
+---
+'@tiny-design/react': patch
+---
+
+Revamp `Divider` with a new API: replace `type`, `align`, and `dashed` with `orientation`, `titlePlacement`, `variant`, `plain`, and `titleGap`.
diff --git a/packages/react/src/divider/__tests__/__snapshots__/divider.test.tsx.snap b/packages/react/src/divider/__tests__/__snapshots__/divider.test.tsx.snap
index 595f90161..7525aab20 100644
--- a/packages/react/src/divider/__tests__/__snapshots__/divider.test.tsx.snap
+++ b/packages/react/src/divider/__tests__/__snapshots__/divider.test.tsx.snap
@@ -3,7 +3,8 @@
exports[` should match the snapshot 1`] = `
diff --git a/packages/react/src/divider/__tests__/divider.test.tsx b/packages/react/src/divider/__tests__/divider.test.tsx
index cb9941fe1..390710559 100644
--- a/packages/react/src/divider/__tests__/divider.test.tsx
+++ b/packages/react/src/divider/__tests__/divider.test.tsx
@@ -16,16 +16,19 @@ describe('', () => {
it('should render horizontal type by default', () => {
const { container } = render();
expect(container.firstChild).toHaveClass('ty-divider_horizontal');
+ expect(container.firstChild).toHaveClass('ty-divider_solid');
+ expect(container.firstChild).toHaveAttribute('aria-orientation', 'horizontal');
});
- it('should render vertical type', () => {
- const { container } = render();
+ it('should render vertical orientation', () => {
+ const { container } = render();
expect(container.firstChild).toHaveClass('ty-divider_vertical');
+ expect(container.firstChild).toHaveAttribute('aria-orientation', 'vertical');
});
- it('should render dashed style', () => {
- const { container } = render();
- expect(container.firstChild).toHaveClass('ty-divider_horizontal-dashed');
+ it('should render variant style', () => {
+ const { container } = render();
+ expect(container.firstChild).toHaveClass('ty-divider_dashed');
});
it('should render with text', () => {
@@ -33,8 +36,37 @@ describe('', () => {
expect(getByText('Section')).toBeInTheDocument();
});
- it('should render text with alignment', () => {
- const { container } = render(Left);
+ it('should render text with title placement', () => {
+ const { container } = render(Left);
+ expect(container.firstChild).toHaveClass('ty-divider_start');
+ expect(container.firstChild).toHaveClass('ty-divider_text');
expect(container.querySelector('.ty-divider_inner-text')).toBeInTheDocument();
});
+
+ it('should render falsy children content', () => {
+ const { container, getByText } = render({0});
+ expect(container.firstChild).toHaveClass('ty-divider_text');
+ expect(getByText('0')).toBeInTheDocument();
+ });
+
+ it('should render plain style', () => {
+ const { container } = render(Plain);
+ expect(container.firstChild).toHaveClass('ty-divider_plain');
+ });
+
+ it('should apply title gap custom property', () => {
+ const { container } = render(Gap);
+ expect(container.firstChild).toHaveStyle('--ty-divider-title-gap: 24px');
+ });
+
+ it('should not render inner text for vertical divider', () => {
+ const { container, queryByText } = render(
+
+ Hidden
+ ,
+ );
+ expect(container.firstChild).not.toHaveClass('ty-divider_text');
+ expect(container.firstChild).not.toHaveClass('ty-divider_start');
+ expect(queryByText('Hidden')).not.toBeInTheDocument();
+ });
});
diff --git a/packages/react/src/divider/demo/AlignTitle.tsx b/packages/react/src/divider/demo/AlignTitle.tsx
index 88cfab238..eb6f7c0d8 100644
--- a/packages/react/src/divider/demo/AlignTitle.tsx
+++ b/packages/react/src/divider/demo/AlignTitle.tsx
@@ -4,16 +4,27 @@ import { Divider } from '@tiny-design/react';
export default function AlignTitleDemo() {
return (
<>
- Left Text
+
+ Account Summary
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
- Right Text
+
+ Recent Activity
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+
+ Archived
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
>
);
-}
\ No newline at end of file
+}
diff --git a/packages/react/src/divider/demo/ContentSection.tsx b/packages/react/src/divider/demo/ContentSection.tsx
new file mode 100644
index 000000000..b5073c817
--- /dev/null
+++ b/packages/react/src/divider/demo/ContentSection.tsx
@@ -0,0 +1,60 @@
+import React from 'react';
+import { Card, Divider, Tag, Text } from '@tiny-design/react';
+
+const rowStyle: React.CSSProperties = {
+ display: 'flex',
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ gap: 12,
+};
+
+export default function ContentSectionDemo() {
+ return (
+
+
+
+
+
Release Checklist
+
+ Prepare the final rollout for the next product update.
+
+
+
v1.12
+
+
+
+ QA Status
+
+
+
+
Visual review
+
+ Tokens, spacing, and states confirmed.
+
+
+
Passed
+
+
+
+ Deployment
+
+
+
+
Production rollout
+
+ Waiting for final approval from release owners.
+
+
+
Pending
+
+
+
+ );
+}
diff --git a/packages/react/src/divider/demo/Horizontal.tsx b/packages/react/src/divider/demo/Horizontal.tsx
index 60ad3af8a..08fb0d356 100644
--- a/packages/react/src/divider/demo/Horizontal.tsx
+++ b/packages/react/src/divider/demo/Horizontal.tsx
@@ -13,16 +13,26 @@ export default function HorizontalDemo() {
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
- With Text
+ Solid Section
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
-
+ Dashed Section
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+ Dotted Section
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+ Quick Actions
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
>
);
-}
\ No newline at end of file
+}
diff --git a/packages/react/src/divider/demo/PlainAndGap.tsx b/packages/react/src/divider/demo/PlainAndGap.tsx
new file mode 100644
index 000000000..3599094ad
--- /dev/null
+++ b/packages/react/src/divider/demo/PlainAndGap.tsx
@@ -0,0 +1,24 @@
+import React from 'react';
+import { Divider } from '@tiny-design/react';
+
+export default function PlainAndGapDemo() {
+ return (
+ <>
+ Default Title Gap
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+ Wide Title Gap
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+ Plain Supporting Text
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti
+ licere mihi ista probare, quae sunt a te dicta? Refert tamen, quo modo.
+
+ >
+ );
+}
diff --git a/packages/react/src/divider/demo/Vertical.tsx b/packages/react/src/divider/demo/Vertical.tsx
index fc22942db..f07a178e2 100644
--- a/packages/react/src/divider/demo/Vertical.tsx
+++ b/packages/react/src/divider/demo/Vertical.tsx
@@ -3,12 +3,12 @@ import { Divider } from '@tiny-design/react';
export default function VerticalDemo() {
return (
- <>
- Text
-
- Link
-
- Link
- >
+
);
-}
\ No newline at end of file
+}
diff --git a/packages/react/src/divider/divider.tsx b/packages/react/src/divider/divider.tsx
index 3244fcd2f..0207acbfc 100755
--- a/packages/react/src/divider/divider.tsx
+++ b/packages/react/src/divider/divider.tsx
@@ -6,24 +6,50 @@ import { DividerProps } from './types';
const Divider = React.memo(React.forwardRef((props, ref) => {
const {
- type = 'horizontal',
- dashed = false,
- align = 'center',
+ orientation = 'horizontal',
+ variant = 'solid',
+ titlePlacement = 'center',
+ plain = false,
+ titleGap,
prefixCls: customisedCls,
className,
children,
+ style,
...otherProps
} = props;
const configContext = useContext(ConfigContext);
const prefixCls = getPrefixCls('divider', configContext.prefixCls, customisedCls);
- const cls = classNames(prefixCls, className, `${prefixCls}_${type}`, `${prefixCls}_${align}`, {
- [`${prefixCls}_${type}-dashed`]: dashed,
- [`${prefixCls}_text`]: children,
- });
+ const hasChildren = children !== null && children !== undefined;
+ const hasInnerText = orientation === 'horizontal' && hasChildren;
+ const cls = classNames(
+ prefixCls,
+ className,
+ `${prefixCls}_${orientation}`,
+ `${prefixCls}_${variant}`,
+ hasInnerText && `${prefixCls}_${titlePlacement}`,
+ {
+ [`${prefixCls}_text`]: hasInnerText,
+ [`${prefixCls}_plain`]: plain,
+ },
+ );
+ const mergedStyle = hasInnerText && titleGap !== undefined
+ ? {
+ ...style,
+ ['--ty-divider-title-gap' as string]:
+ typeof titleGap === 'number' ? `${titleGap}px` : titleGap,
+ }
+ : style;
return (
-
- {children &&
{children}}
+
+ {hasInnerText && {children}}
);
}));
diff --git a/packages/react/src/divider/index.md b/packages/react/src/divider/index.md
index 59da1095b..7255f5364 100644
--- a/packages/react/src/divider/index.md
+++ b/packages/react/src/divider/index.md
@@ -1,7 +1,11 @@
import AlignTitleDemo from './demo/AlignTitle';
import AlignTitleSource from './demo/AlignTitle.tsx?raw';
+import ContentSectionDemo from './demo/ContentSection';
+import ContentSectionSource from './demo/ContentSection.tsx?raw';
import HorizontalDemo from './demo/Horizontal';
import HorizontalSource from './demo/Horizontal.tsx?raw';
+import PlainAndGapDemo from './demo/PlainAndGap';
+import PlainAndGapSource from './demo/PlainAndGap.tsx?raw';
import VerticalDemo from './demo/Vertical';
import VerticalSource from './demo/Vertical.tsx?raw';
@@ -28,7 +32,7 @@ import { Divider } from 'tiny-design';
### Horizontal
-Divider default type is `horizontal`. Support inner text inside Divider.
+Divider defaults to horizontal. Horizontal dividers support inner text, line variants, and plain text styling.
@@ -37,10 +41,19 @@ Divider default type is `horizontal`. Support inner text inside Divider.
### Vertical
-Use `type="vertical"` make it vertical.
+Use `orientation="vertical"` to render a vertical divider.
+
+
+
+### Plain And Gap
+
+Use `plain` to reduce emphasis and `titleGap` to control title spacing.
+
+
+
@@ -48,20 +61,31 @@ Use `type="vertical"` make it vertical.
### Align Title
-Set orientation of divider to left or right, default is `center`.
+Set the title placement to `start`, `center`, or `end`. This only applies to horizontal dividers with inner text.
+
+
+
+### In Content
+
+Use dividers as lightweight section labels inside cards, settings panels, or summaries.
+
+
+
## Props
-| Property | Description | Type | Default |
-| --------- | -------------------------------- | ---------------------------------------------- | ------------ |
-| type | direction type of divider | enum: `horizontal` | `vertical` | `horizontal` |
-| dashed | whether line is dashed | boolean | false |
-| align | position of title inside divider | enum: `left` | `right` | `center` | `center` |
-| style | style object of container object | CSSProperties | - |
-| className | className of container | string | - |
\ No newline at end of file
+| Property | Description | Type | Default |
+| -------------- | ------------------------------------------------------ | -------------------------------------------- | -------------- |
+| orientation | orientation of divider | enum: `horizontal` | `vertical` | `horizontal` |
+| variant | line style variant | enum: `solid` | `dashed` | `dotted` | `solid` |
+| titlePlacement | position of title inside horizontal divider with text | enum: `start` | `center` | `end` | `center` |
+| plain | whether divider text uses plain emphasis | boolean | false |
+| titleGap | horizontal gap between divider title and line | string | number | token value |
+| style | style object of container | CSSProperties | - |
+| className | className of container | string | - |
diff --git a/packages/react/src/divider/index.zh_CN.md b/packages/react/src/divider/index.zh_CN.md
index 1961b0134..f2e30c389 100644
--- a/packages/react/src/divider/index.zh_CN.md
+++ b/packages/react/src/divider/index.zh_CN.md
@@ -1,7 +1,11 @@
import AlignTitleDemo from './demo/AlignTitle';
import AlignTitleSource from './demo/AlignTitle.tsx?raw';
+import ContentSectionDemo from './demo/ContentSection';
+import ContentSectionSource from './demo/ContentSection.tsx?raw';
import HorizontalDemo from './demo/Horizontal';
import HorizontalSource from './demo/Horizontal.tsx?raw';
+import PlainAndGapDemo from './demo/PlainAndGap';
+import PlainAndGapSource from './demo/PlainAndGap.tsx?raw';
import VerticalDemo from './demo/Vertical';
import VerticalSource from './demo/Vertical.tsx?raw';
@@ -28,7 +32,7 @@ import { Divider } from 'tiny-design';
### 水平分割线
-分割线默认类型为 `horizontal`。支持在分割线内添加文字。
+分割线默认为水平。水平分割线支持中间文字、线型变体和弱化标题样式。
@@ -37,10 +41,19 @@ import { Divider } from 'tiny-design';
### 垂直分割线
-使用 `type="vertical"` 使其垂直。
+使用 `orientation="vertical"` 使其垂直。
+
+
+
+### 弱化标题与间距
+
+使用 `plain` 降低标题强调度,使用 `titleGap` 调整标题与线之间的间距。
+
+
+
@@ -48,20 +61,31 @@ import { Divider } from 'tiny-design';
### 对齐标题
-设置分割线标题的位置,默认为 `center`。
+设置分割线标题的位置,可选 `start`、`center`、`end`,默认为 `center`。仅对带文本的水平分割线生效。
+
+
+
+### 内容分组
+
+在卡片、设置面板或摘要信息中,分割线也可以作为轻量级分组标题使用。
+
+
+
## Props
-| 属性 | 说明 | 类型 | 默认值 |
-| --------- | -------------------------------- | ---------------------------------------------- | ------------ |
-| type | 分割线方向类型 | enum: `horizontal` | `vertical` | `horizontal` |
-| dashed | 是否为虚线 | boolean | false |
-| align | 分割线中标题的位置 | enum: `left` | `right` | `center` | `center` |
-| style | 容器的样式对象 | CSSProperties | - |
-| className | 容器的 className | string | - |
\ No newline at end of file
+| 属性 | 说明 | 类型 | 默认值 |
+| -------------- | ---------------------------------------------- | --------------------------------------------- | ------------- |
+| orientation | 分割线方向 | enum: `horizontal` | `vertical` | `horizontal` |
+| variant | 分割线样式变体 | enum: `solid` | `dashed` | `dotted` | `solid` |
+| titlePlacement | 带文本的水平分割线中标题的位置 | enum: `start` | `center` | `end` | `center` |
+| plain | 是否使用弱化的标题样式 | boolean | false |
+| titleGap | 分割线标题与线之间的水平间距 | string | number | token 值 |
+| style | 容器的样式对象 | CSSProperties | - |
+| className | 容器的 className | string | - |
diff --git a/packages/react/src/divider/style/index.scss b/packages/react/src/divider/style/index.scss
index 69175c160..df73a2819 100755
--- a/packages/react/src/divider/style/index.scss
+++ b/packages/react/src/divider/style/index.scss
@@ -5,41 +5,34 @@
line-height: var(--ty-divider-line-height);
box-sizing: border-box;
padding: 0;
+ border: 0;
list-style: none;
+ --ty-divider-border-style: solid;
+
&_vertical {
margin: var(--ty-divider-vertical-margin);
display: inline-block;
height: var(--ty-divider-vertical-height);
- width: 1px;
+ width: 0;
vertical-align: middle;
- position: relative;
- top: var(--ty-divider-vertical-offset);
- background: var(--ty-divider-color);
-
- &-dashed {
- background: none;
- border-left: 1px dashed var(--ty-divider-color);
- }
+ border-left: 1px var(--ty-divider-border-style) var(--ty-divider-color);
}
&_horizontal {
display: block;
- height: 1px;
+ height: 0;
width: 100%;
margin: var(--ty-divider-horizontal-margin);
- background: var(--ty-divider-color);
-
- &-dashed:not(.#{$prefix}-divider_text) {
- background: none;
- border-top: 1px dashed var(--ty-divider-color);
- }
+ border-top: 1px var(--ty-divider-border-style) var(--ty-divider-color);
}
&_text {
- display: table;
+ display: flex;
+ align-items: center;
+ width: 100%;
white-space: nowrap;
- text-align: center;
+ border-top: 0;
background: transparent;
font-weight: 500;
color: var(--ty-divider-text-color);
@@ -47,34 +40,38 @@
&::before,
&::after {
content: '';
- display: table-cell;
- position: relative;
- top: 50%;
- width: 50%;
- border-top: 1px solid var(--ty-divider-color);
- transform: translateY(50%);
+ flex: 1 1 auto;
+ height: 0;
+ border-top: 1px var(--ty-divider-border-style) var(--ty-divider-color);
}
}
- &_left::before,
- &_right::after {
- width: 5%;
+ &_start::before,
+ &_end::after {
+ flex: 0 0 5%;
}
- &_left::after,
- &_right::before {
- width: 95%;
+ &_start::after,
+ &_end::before {
+ flex: 1 1 auto;
}
&_inner-text {
- display: inline-block;
- padding: var(--ty-divider-inner-text-padding);
+ display: inline-flex;
+ align-items: center;
+ padding: 0 var(--ty-divider-title-gap, 10px);
+ line-height: 1;
+ }
+
+ &_plain {
+ font-weight: 400;
}
&_dashed {
- &::before,
- &::after {
- border-top-style: dashed;
- }
+ --ty-divider-border-style: dashed;
+ }
+
+ &_dotted {
+ --ty-divider-border-style: dotted;
}
}
diff --git a/packages/react/src/divider/types.ts b/packages/react/src/divider/types.ts
index 4e6f0c3f1..da583f804 100644
--- a/packages/react/src/divider/types.ts
+++ b/packages/react/src/divider/types.ts
@@ -1,13 +1,17 @@
import React from 'react';
import { BaseProps, DirectionType } from '../_utils/props';
-export type DivideAlign = 'left' | 'right' | 'center';
+export type DividerOrientation = DirectionType;
+export type DividerTitlePlacement = 'start' | 'center' | 'end';
+export type DividerVariant = 'solid' | 'dashed' | 'dotted';
export interface DividerProps
extends BaseProps,
React.PropsWithoutRef
{
- type?: DirectionType;
- dashed?: boolean;
- align?: DivideAlign;
+ orientation?: DividerOrientation;
+ variant?: DividerVariant;
+ titlePlacement?: DividerTitlePlacement;
+ plain?: boolean;
+ titleGap?: string | number;
children?: React.ReactNode;
}
diff --git a/packages/react/src/form/demo/ValidateTrigger.tsx b/packages/react/src/form/demo/ValidateTrigger.tsx
index c599a13ed..aba8e2d37 100644
--- a/packages/react/src/form/demo/ValidateTrigger.tsx
+++ b/packages/react/src/form/demo/ValidateTrigger.tsx
@@ -4,7 +4,7 @@ import { Form, Input, InputPassword, Button, Divider } from '@tiny-design/react'
export default function ValidateTriggerDemo() {
return (
<>
- onChange
+ onChange
- onBlur
+ onBlur
- onSubmit
+ onSubmit
>
);
-}
\ No newline at end of file
+}
diff --git a/packages/react/src/grid/demo/Alignment.tsx b/packages/react/src/grid/demo/Alignment.tsx
index 48a91953d..4d9f0b436 100644
--- a/packages/react/src/grid/demo/Alignment.tsx
+++ b/packages/react/src/grid/demo/Alignment.tsx
@@ -43,7 +43,7 @@ export default function AlignmentDemo() {
return (
<>
- Align Top
+ Align Top
col-4
col-4
@@ -51,7 +51,7 @@ export default function AlignmentDemo() {
col-4
- Align Center
+ Align Center
col-4
col-4
@@ -59,7 +59,7 @@ export default function AlignmentDemo() {
col-4
- Align Bottom
+ Align Bottom
col-4
col-4
diff --git a/packages/react/src/menu/__tests__/__snapshots__/menu.test.tsx.snap b/packages/react/src/menu/__tests__/__snapshots__/menu.test.tsx.snap
index 545c33132..ceb47ff4f 100644
--- a/packages/react/src/menu/__tests__/__snapshots__/menu.test.tsx.snap
+++ b/packages/react/src/menu/__tests__/__snapshots__/menu.test.tsx.snap
@@ -4,7 +4,7 @@ exports[` should match the snapshot 1`] = `
+ );
+
+ const customersSubMenu = screen.getByText('Customers').closest('.ty-menu-sub') as HTMLElement;
+ fireEvent.mouseEnter(customersSubMenu);
+ act(() => {
+ jest.advanceTimersByTime(250);
+ });
+
+ const lifecycleTitle = screen.getByText('Lifecycle').closest('.ty-menu-sub__title') as HTMLElement;
+ Object.defineProperty(lifecycleTitle, 'offsetWidth', {
+ configurable: true,
+ value: 240,
+ });
+
+ fireEvent.mouseEnter(lifecycleTitle.closest('.ty-menu-sub') as HTMLElement);
+ act(() => {
+ jest.advanceTimersByTime(250);
+ });
+
+ expect(screen.getByText('New Users').closest('.ty-menu-sub__list_popup')).toHaveStyle({
+ minWidth: '240px',
+ });
+ });
+
it('should follow global theme when theme prop is not provided and respect explicit theme override', () => {
const { container, rerender } = render(
diff --git a/packages/react/src/menu/demo/Horizontal.tsx b/packages/react/src/menu/demo/Horizontal.tsx
index 0e3d9deb4..7642b1e78 100644
--- a/packages/react/src/menu/demo/Horizontal.tsx
+++ b/packages/react/src/menu/demo/Horizontal.tsx
@@ -3,7 +3,7 @@ import { Menu, Tag } from '@tiny-design/react';
export default function HorizontalDemo() {
return (
-