@ticatec/topside-elements 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/general/button/IconButton.svelte +24 -2
- package/dist/general/button/IconButton.svelte.d.ts +13 -0
- package/dist/general/button/IconButton_README.md +27 -2
- package/dist/general/button/IconButton_README_CN.md +27 -2
- package/dist/general/button/index.d.ts +2 -2
- package/dist/general/button/index.js +1 -1
- package/dist/topside-elements.css +18 -0
- package/docs/components/README.md +3 -3
- package/docs/components/icon-button/README.md +16 -0
- package/docs/components/icon-button/example.svelte +2 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
|
|
5
5
|
type ButtonType = 'default' | 'primary' | 'secondary' | 'third' | 'forth';
|
|
6
|
+
export type IconButtonVariant = 'circle' | 'round';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
type?: ButtonType;
|
|
@@ -18,6 +19,18 @@
|
|
|
18
19
|
children?: Snippet;
|
|
19
20
|
tabindex?: number;
|
|
20
21
|
outer?: boolean;
|
|
22
|
+
/** 形状变体:'circle' (默认正圆) | 'round' (圆角矩形) */
|
|
23
|
+
variant?: IconButtonVariant;
|
|
24
|
+
/** 形状别名,支持与 variant 相同的取值 */
|
|
25
|
+
shape?: IconButtonVariant;
|
|
26
|
+
/** 是否为圆角(round corner 便捷布尔属性) */
|
|
27
|
+
round?: boolean;
|
|
28
|
+
/** 是否无边框 */
|
|
29
|
+
borderless?: boolean;
|
|
30
|
+
/** 是否有边框(默认为 true,设为 false 时等同于 borderless) */
|
|
31
|
+
border?: boolean;
|
|
32
|
+
/** 是否有边框(border 别名) */
|
|
33
|
+
bordered?: boolean;
|
|
21
34
|
}
|
|
22
35
|
|
|
23
36
|
let {
|
|
@@ -32,9 +45,18 @@
|
|
|
32
45
|
theme,
|
|
33
46
|
children,
|
|
34
47
|
tabindex = -1,
|
|
35
|
-
outer = true
|
|
48
|
+
outer = true,
|
|
49
|
+
variant = 'circle',
|
|
50
|
+
shape,
|
|
51
|
+
round = false,
|
|
52
|
+
borderless = false,
|
|
53
|
+
border = true,
|
|
54
|
+
bordered = true
|
|
36
55
|
}: Props = $props();
|
|
37
56
|
|
|
57
|
+
const isRound = $derived(round || shape === 'round' || variant === 'round');
|
|
58
|
+
const shapeClass = $derived(isRound ? 'round' : 'circle');
|
|
59
|
+
const isBorderless = $derived(borderless || !border || !bordered);
|
|
38
60
|
|
|
39
61
|
const handleClick = (e: MouseEvent) => {
|
|
40
62
|
if (!disabled) {
|
|
@@ -48,7 +70,7 @@
|
|
|
48
70
|
|
|
49
71
|
</script>
|
|
50
72
|
|
|
51
|
-
<button type={htmlType} class="topside-button icon-button {size} {type} {theme}" class:outer class:no-outer={!outer} {style} class:disabled {disabled}
|
|
73
|
+
<button type={htmlType} class="topside-button icon-button {size} {type} {shapeClass} {theme}" class:outer class:no-outer={!outer} class:borderless={isBorderless} {style} class:disabled {disabled}
|
|
52
74
|
tabindex={disabled ? -1 : tabindex} data-tip={disabled ? null : tooltip} onclick={handleClick}>
|
|
53
75
|
{#if children}
|
|
54
76
|
{@render children()}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Size } from "../../types";
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
type ButtonType = 'default' | 'primary' | 'secondary' | 'third' | 'forth';
|
|
4
|
+
export type IconButtonVariant = 'circle' | 'round';
|
|
4
5
|
interface Props {
|
|
5
6
|
type?: ButtonType;
|
|
6
7
|
htmlType?: 'button' | 'submit' | 'reset';
|
|
@@ -15,6 +16,18 @@ interface Props {
|
|
|
15
16
|
children?: Snippet;
|
|
16
17
|
tabindex?: number;
|
|
17
18
|
outer?: boolean;
|
|
19
|
+
/** 形状变体:'circle' (默认正圆) | 'round' (圆角矩形) */
|
|
20
|
+
variant?: IconButtonVariant;
|
|
21
|
+
/** 形状别名,支持与 variant 相同的取值 */
|
|
22
|
+
shape?: IconButtonVariant;
|
|
23
|
+
/** 是否为圆角(round corner 便捷布尔属性) */
|
|
24
|
+
round?: boolean;
|
|
25
|
+
/** 是否无边框 */
|
|
26
|
+
borderless?: boolean;
|
|
27
|
+
/** 是否有边框(默认为 true,设为 false 时等同于 borderless) */
|
|
28
|
+
border?: boolean;
|
|
29
|
+
/** 是否有边框(border 别名) */
|
|
30
|
+
bordered?: boolean;
|
|
18
31
|
}
|
|
19
32
|
declare const IconButton: import("svelte").Component<Props, {}, "">;
|
|
20
33
|
type IconButton = ReturnType<typeof IconButton>;
|
|
@@ -37,7 +37,12 @@ const handleClick = (event) => {
|
|
|
37
37
|
|------|------|---------|-------------|
|
|
38
38
|
| `type` | `'default' \| 'primary' \| 'secondary' \| 'third' \| 'forth'` | `'default'` | Button type/style |
|
|
39
39
|
| `disabled` | `boolean` | `false` | Whether the button is disabled |
|
|
40
|
-
| `size` | `'
|
|
40
|
+
| `size` | `'large' \| 'medium' \| 'small'` | `'medium'` | Button size |
|
|
41
|
+
| `variant` | `'circle' \| 'round'` | `'circle'` | Button shape variant: `'circle'` for circular, `'round'` for round corner (rounded square) |
|
|
42
|
+
| `shape` | `'circle' \| 'round'` | `'circle'` | Shape alias, supports the same values as `variant` |
|
|
43
|
+
| `round` | `boolean` | `false` | Shorthand boolean for rounded corner (equivalent to `variant="round"`) |
|
|
44
|
+
| `borderless` | `boolean` | `false` | Whether the button is borderless |
|
|
45
|
+
| `border` | `boolean` | `true` | Whether the button has a border (setting `false` is equivalent to `borderless`) |
|
|
41
46
|
| `style` | `string` | `''` | Custom CSS styles |
|
|
42
47
|
| `icon` | `string` | `''` | Icon class name (e.g., FontAwesome classes) |
|
|
43
48
|
| `theme` | `string` | - | Theme variant |
|
|
@@ -45,7 +50,27 @@ const handleClick = (event) => {
|
|
|
45
50
|
| `onclick` | `(event: MouseEvent) => void` | - | Click event handler |
|
|
46
51
|
| `children` | `Snippet` | - | Custom icon content snippet |
|
|
47
52
|
| `tabindex` | `number` | `-1` | Tab index (defaults to -1 so button does not take Tab focus) |
|
|
48
|
-
| `outer` | `boolean` | `true` | Whether to show outer frame/ring when focused or active (defaults to true; set to false to remove focus/active outer frame) |
|
|
53
|
+
| `outer` | `boolean` | `true` | Whether to show outer frame/ring when focused or active (defaults to true; set to false to remove focus/active outer frame and border) |
|
|
54
|
+
|
|
55
|
+
## Shape and Border
|
|
56
|
+
|
|
57
|
+
By default, IconButton renders as a circle (`circle`) with a subtle border. You can set it to a rounded corner square via `variant="round"` or `round={true}`, and remove the border with `borderless={true}` or `border={false}`.
|
|
58
|
+
|
|
59
|
+
```svelte
|
|
60
|
+
<!-- Default circular with border -->
|
|
61
|
+
<IconButton icon="icon_google_add" type="primary" />
|
|
62
|
+
|
|
63
|
+
<!-- Round corner -->
|
|
64
|
+
<IconButton icon="icon_google_add" type="primary" variant="round" />
|
|
65
|
+
<!-- Or using the round shorthand boolean -->
|
|
66
|
+
<IconButton icon="icon_google_add" type="primary" round />
|
|
67
|
+
|
|
68
|
+
<!-- Borderless circle -->
|
|
69
|
+
<IconButton icon="icon_google_favorite" type="primary" borderless={true} />
|
|
70
|
+
|
|
71
|
+
<!-- Borderless round corner -->
|
|
72
|
+
<IconButton icon="icon_google_favorite" type="primary" variant="round" borderless={true} />
|
|
73
|
+
```
|
|
49
74
|
|
|
50
75
|
## Button Types
|
|
51
76
|
|
|
@@ -37,7 +37,12 @@ const handleClick = (event) => {
|
|
|
37
37
|
|------|------|---------|-------------|
|
|
38
38
|
| `type` | `'default' \| 'primary' \| 'secondary' \| 'third' \| 'forth'` | `'default'` | 按钮类型/样式 |
|
|
39
39
|
| `disabled` | `boolean` | `false` | 是否禁用按钮 |
|
|
40
|
-
| `size` | `'
|
|
40
|
+
| `size` | `'large' \| 'medium' \| 'small'` | `'medium'` | 按钮尺寸 |
|
|
41
|
+
| `variant` | `'circle' \| 'round'` | `'circle'` | 按钮形状变体:`'circle'` 为正圆,`'round'` 为圆角矩形 |
|
|
42
|
+
| `shape` | `'circle' \| 'round'` | `'circle'` | 形状别名,支持与 `variant` 相同的取值 |
|
|
43
|
+
| `round` | `boolean` | `false` | 是否为圆角矩形(等同于 `variant="round"`) |
|
|
44
|
+
| `borderless` | `boolean` | `false` | 是否无边框 |
|
|
45
|
+
| `border` | `boolean` | `true` | 是否有边框(设为 `false` 时等同于 `borderless`) |
|
|
41
46
|
| `style` | `string` | `''` | 自定义CSS样式 |
|
|
42
47
|
| `icon` | `string` | `''` | 图标类名(如FontAwesome类) |
|
|
43
48
|
| `theme` | `string` | - | 主题变体 |
|
|
@@ -45,7 +50,27 @@ const handleClick = (event) => {
|
|
|
45
50
|
| `onclick` | `(event: MouseEvent) => void` | - | 点击事件处理器 |
|
|
46
51
|
| `children` | `Snippet` | - | 自定义图标内容片段 |
|
|
47
52
|
| `tabindex` | `number` | `-1` | Tab 键导航顺序(默认为 -1,取消 Tab 键停留) |
|
|
48
|
-
| `outer` | `boolean` | `true` | focused / active 状态时是否带外框(默认为 true,设为 false
|
|
53
|
+
| `outer` | `boolean` | `true` | focused / active 状态时是否带外框(默认为 true,设为 false 时去除聚焦/激活外框与边框) |
|
|
54
|
+
|
|
55
|
+
## 形状与边框
|
|
56
|
+
|
|
57
|
+
IconButton 默认呈现为正圆(`circle`)且带有细边框。你可以通过 `variant="round"` 或 `round={true}` 将其设为圆角矩形(round corner),并通过 `borderless={true}` 或 `border={false}` 设置为无边框。
|
|
58
|
+
|
|
59
|
+
```svelte
|
|
60
|
+
<!-- 默认正圆带边框 -->
|
|
61
|
+
<IconButton icon="icon_google_add" type="primary" />
|
|
62
|
+
|
|
63
|
+
<!-- 圆角矩形 (round corner) -->
|
|
64
|
+
<IconButton icon="icon_google_add" type="primary" variant="round" />
|
|
65
|
+
<!-- 或使用便捷布尔属性 -->
|
|
66
|
+
<IconButton icon="icon_google_add" type="primary" round />
|
|
67
|
+
|
|
68
|
+
<!-- 无边框正圆 -->
|
|
69
|
+
<IconButton icon="icon_google_favorite" type="primary" borderless={true} />
|
|
70
|
+
|
|
71
|
+
<!-- 无边框圆角矩形 -->
|
|
72
|
+
<IconButton icon="icon_google_favorite" type="primary" variant="round" borderless={true} />
|
|
73
|
+
```
|
|
49
74
|
|
|
50
75
|
## 按钮类型
|
|
51
76
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Button from "./Button.svelte";
|
|
2
|
-
import IconButton from "./IconButton.svelte";
|
|
2
|
+
import IconButton, { type IconButtonVariant } from "./IconButton.svelte";
|
|
3
3
|
import TextButton from "./TextButton.svelte";
|
|
4
4
|
import type { ButtonType } from "../../types";
|
|
5
5
|
export default Button;
|
|
6
6
|
export { IconButton };
|
|
7
7
|
export { TextButton };
|
|
8
|
-
export type { ButtonType };
|
|
8
|
+
export type { ButtonType, IconButtonVariant };
|
|
@@ -943,6 +943,24 @@
|
|
|
943
943
|
.topside-button.icon-button.small i {
|
|
944
944
|
font-size: 16px;
|
|
945
945
|
}
|
|
946
|
+
.topside-button.icon-button.circle {
|
|
947
|
+
border-radius: 50%;
|
|
948
|
+
}
|
|
949
|
+
.topside-button.icon-button.round, .topside-button.icon-button.round-corner {
|
|
950
|
+
border-radius: var(--topside-button-radius, var(--radius-md, 4px));
|
|
951
|
+
}
|
|
952
|
+
.topside-button.icon-button.borderless {
|
|
953
|
+
border-color: transparent !important;
|
|
954
|
+
}
|
|
955
|
+
.topside-button.icon-button.borderless.disabled {
|
|
956
|
+
border-color: transparent !important;
|
|
957
|
+
}
|
|
958
|
+
.topside-button.icon-button.no-outer {
|
|
959
|
+
border-color: transparent !important;
|
|
960
|
+
}
|
|
961
|
+
.topside-button.icon-button.no-outer.disabled {
|
|
962
|
+
border-color: transparent !important;
|
|
963
|
+
}
|
|
946
964
|
.topside-button.icon-button.no-outer:focus, .topside-button.icon-button.no-outer:focus-visible, .topside-button.icon-button.no-outer:active {
|
|
947
965
|
outline: none !important;
|
|
948
966
|
box-shadow: none !important;
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
| [Accordion](./accordion/README.md) | `@ticatec/topside-elements/Accordion` | [示例](./accordion/example.svelte) | 5 |
|
|
110
110
|
| [Card](./card/README.md) | `@ticatec/topside-elements/Card` | [示例](./card/example.svelte) | 11 |
|
|
111
111
|
| [ConciseDataTable](./concise-data-table/README.md) | `@ticatec/topside-elements/ConciseDataTable` | [示例](./concise-data-table/example.svelte) | 10 |
|
|
112
|
-
| [ListBox](./list-box/README.md) | `@ticatec/topside-elements/ListBox` | [示例](./list-box/example.svelte) |
|
|
113
|
-
| [TreeView](./tree-view/README.md) | `@ticatec/topside-elements/TreeView` | [示例](./tree-view/example.svelte) |
|
|
112
|
+
| [ListBox](./list-box/README.md) | `@ticatec/topside-elements/ListBox` | [示例](./list-box/example.svelte) | 22 |
|
|
113
|
+
| [TreeView](./tree-view/README.md) | `@ticatec/topside-elements/TreeView` | [示例](./tree-view/example.svelte) | 19 |
|
|
114
114
|
|
|
115
115
|
## 通用
|
|
116
116
|
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
| --- | --- | --- | ---: |
|
|
119
119
|
| [Button](./button/README.md) | `@ticatec/topside-elements/Button` | [示例](./button/example.svelte) | 14 |
|
|
120
120
|
| [Icon](./icon/README.md) | `@ticatec/topside-elements/Icon` | [示例](./icon/example.svelte) | 8 |
|
|
121
|
-
| [IconButton](./icon-button/README.md) | `@ticatec/topside-elements/IconButton` | [示例](./icon-button/example.svelte) |
|
|
121
|
+
| [IconButton](./icon-button/README.md) | `@ticatec/topside-elements/IconButton` | [示例](./icon-button/example.svelte) | 18 |
|
|
122
122
|
| [Separator](./separator/README.md) | `@ticatec/topside-elements/Separator` | [示例](./separator/example.svelte) | 2 |
|
|
123
123
|
| [Split](./split/README.md) | `@ticatec/topside-elements/Split` | [示例](./split/example.svelte) | 10 |
|
|
124
124
|
| [Tag](./tag/README.md) | `@ticatec/topside-elements/Tag` | [示例](./tag/example.svelte) | 10 |
|
|
@@ -33,6 +33,12 @@ import IconButton from '@ticatec/topside-elements/IconButton';
|
|
|
33
33
|
| `children` | 是 | `Snippet` | 否 | `undefined` | 否 | Svelte Snippet 子内容,用于自定义组件主体。 |
|
|
34
34
|
| `tabindex` | 否 | `number` | 否 | `-1` | 否 | 可选配置,具体取值范围和数据结构见类型列。 |
|
|
35
35
|
| `outer` | 否 | `boolean` | 否 | `true` | 否 | 可选配置,具体取值范围和数据结构见类型列。 |
|
|
36
|
+
| `variant` | 是 | `IconButtonVariant` | 否 | `'circle'` | 否 | 形状变体:'circle' (默认正圆) \| 'round' (圆角矩形) |
|
|
37
|
+
| `shape` | 否 | `IconButtonVariant` | 否 | `undefined` | 否 | 形状别名,支持与 variant 相同的取值 |
|
|
38
|
+
| `round` | 否 | `boolean` | 否 | `false` | 否 | 是否为圆角(round corner 便捷布尔属性) |
|
|
39
|
+
| `borderless` | 否 | `boolean` | 否 | `false` | 否 | 是否无边框 |
|
|
40
|
+
| `border` | 否 | `boolean` | 否 | `true` | 否 | 是否有边框(默认为 true,设为 false 时等同于 borderless) |
|
|
41
|
+
| `bordered` | 否 | `boolean` | 否 | `true` | 否 | 是否有边框(border 别名) |
|
|
36
42
|
|
|
37
43
|
> 组件的“可绑定”表示源码使用了 Svelte 5 的 `$bindable`;服务的“响应式”表示成员使用了 `$state`。复杂类型请同时参考 TypeScript 自动补全。
|
|
38
44
|
|
|
@@ -62,6 +68,14 @@ Svelte Snippet 子内容,用于自定义组件主体。
|
|
|
62
68
|
- 默认值:`undefined`
|
|
63
69
|
- 示例写法:`children={children}`
|
|
64
70
|
|
|
71
|
+
### `variant`
|
|
72
|
+
|
|
73
|
+
形状变体:'circle' (默认正圆) | 'round' (圆角矩形)
|
|
74
|
+
|
|
75
|
+
- 类型:`IconButtonVariant`
|
|
76
|
+
- 默认值:`'circle'`
|
|
77
|
+
- 示例写法:`variant="circle"`
|
|
78
|
+
|
|
65
79
|
## 相关类型定义
|
|
66
80
|
|
|
67
81
|
以下定义帮助理解复杂属性的数据结构;其中部分辅助类型属于内部实现,不一定是独立导出入口。
|
|
@@ -88,8 +102,10 @@ export type Size = 'small' | 'medium' | 'large';
|
|
|
88
102
|
|
|
89
103
|
<IconButton
|
|
90
104
|
onclick={async (...args: any[]) => { console.log('onclick', ...args); return true; }}
|
|
105
|
+
variant="circle"
|
|
91
106
|
disabled={false}
|
|
92
107
|
size="small"
|
|
108
|
+
round={true}
|
|
93
109
|
>
|
|
94
110
|
<div>在这里放置子内容</div>
|
|
95
111
|
</IconButton>
|
package/package.json
CHANGED