@lumen-design/card 0.0.2

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.
@@ -0,0 +1,59 @@
1
+ <script lang="ts">
2
+ import type { CardProps, StyleValue } from './types'
3
+
4
+ const styleToString = (value?: StyleValue): string | undefined => {
5
+ if (!value) return undefined
6
+ if (typeof value === 'string') return value
7
+ return Object.entries(value)
8
+ .map(([key, val]) => `${key.replace(/([A-Z])/g, '-$1').toLowerCase()}:${val}`)
9
+ .join(';')
10
+ }
11
+
12
+ let {
13
+ header,
14
+ footer,
15
+ bodyStyle,
16
+ headerClass = '',
17
+ bodyClass = '',
18
+ footerClass = '',
19
+ shadow = 'always',
20
+ children,
21
+ class: cls = '',
22
+ ...attrs
23
+ }: CardProps = $props()
24
+
25
+ const shadowClass = $derived(shadow !== 'always' ? ` is-${shadow}-shadow` : '')
26
+ const cardClasses = $derived(`lm-card${shadowClass}${cls ? ` ${cls}` : ''}`)
27
+ const headerClasses = $derived(`lm-card__header${headerClass ? ` ${headerClass}` : ''}`)
28
+ const bodyClasses = $derived(`lm-card__body${bodyClass ? ` ${bodyClass}` : ''}`)
29
+ const footerClasses = $derived(`lm-card__footer${footerClass ? ` ${footerClass}` : ''}`)
30
+ const bodyStyleText = $derived(styleToString(bodyStyle))
31
+ </script>
32
+
33
+ <div class={cardClasses} {...attrs}>
34
+ {#if header}
35
+ <div class={headerClasses}>
36
+ {#if typeof header === 'string'}
37
+ {header}
38
+ {:else}
39
+ {@render header()}
40
+ {/if}
41
+ </div>
42
+ {/if}
43
+
44
+ <div class={bodyClasses} style={bodyStyleText}>
45
+ {#if children}
46
+ {@render children()}
47
+ {/if}
48
+ </div>
49
+
50
+ {#if footer}
51
+ <div class={footerClasses}>
52
+ {#if typeof footer === 'string'}
53
+ {footer}
54
+ {:else}
55
+ {@render footer()}
56
+ {/if}
57
+ </div>
58
+ {/if}
59
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { CardProps } from './types';
2
+ declare const Card: import("svelte").Component<CardProps, {}, "">;
3
+ type Card = ReturnType<typeof Card>;
4
+ export default Card;
@@ -0,0 +1,4 @@
1
+ import Card from './Card.svelte';
2
+ export { Card };
3
+ export * from './types';
4
+ export default Card;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import Card from './Card.svelte';
2
+ export { Card };
3
+ export * from './types';
4
+ export default Card;
@@ -0,0 +1,26 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ /** Card 阴影显示时机 */
4
+ export type CardShadow = 'always' | 'hover' | 'never';
5
+ export type StyleValue = string | Record<string, string | number>;
6
+ /** Card 属性 */
7
+ export interface CardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'class'> {
8
+ /** 卡片标题(也可通过 header snippet 传入) */
9
+ header?: string | Snippet;
10
+ /** 卡片底部(也可通过 footer snippet 传入) */
11
+ footer?: string | Snippet;
12
+ /** body 的 CSS 样式 */
13
+ bodyStyle?: StyleValue;
14
+ /** header 自定义类名 */
15
+ headerClass?: string;
16
+ /** body 自定义类名 */
17
+ bodyClass?: string;
18
+ /** footer 自定义类名 */
19
+ footerClass?: string;
20
+ /** 阴影显示时机 */
21
+ shadow?: CardShadow;
22
+ /** 子内容 */
23
+ children?: Snippet;
24
+ /** 自定义类名 */
25
+ class?: string;
26
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@lumen-design/card",
3
+ "version": "0.0.2",
4
+ "description": "Card component for Lumen UI",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "svelte-package -i src -o dist --types",
21
+ "build:watch": "svelte-package -i src -o dist --types -w"
22
+ },
23
+ "devDependencies": {
24
+ "@sveltejs/package": "^2.5.7",
25
+ "svelte": "5.48.2"
26
+ },
27
+ "peerDependencies": {
28
+ "svelte": "^5.0.0"
29
+ }
30
+ }