@lumen-design/descriptions 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,69 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+ import type { DescriptionsSize, DescriptionsDirection } from './types'
4
+ import { setContext } from 'svelte'
5
+ import { DESCRIPTIONS_CONTEXT_KEY, type DescriptionsContext } from './DescriptionsContext'
6
+
7
+ interface DescriptionsProps {
8
+ title?: string | Snippet
9
+ extra?: Snippet
10
+ border?: boolean
11
+ column?: number
12
+ direction?: DescriptionsDirection
13
+ size?: DescriptionsSize
14
+ children?: Snippet
15
+ class?: string
16
+ }
17
+
18
+ let { title, extra, border = false, column = 3, direction = 'horizontal', size = 'default', children, class: cls = '', ...attrs }: DescriptionsProps = $props()
19
+
20
+ const context: DescriptionsContext = {
21
+ get border() {
22
+ return border
23
+ },
24
+ get column() {
25
+ return column
26
+ },
27
+ get direction() {
28
+ return direction
29
+ },
30
+ get size() {
31
+ return size
32
+ },
33
+ }
34
+
35
+ setContext(DESCRIPTIONS_CONTEXT_KEY, context)
36
+
37
+ const classes = $derived(`lm-descriptions lm-descriptions--${size}${border ? ' is-bordered' : ''}${cls ? ` ${cls}` : ''}`)
38
+ </script>
39
+
40
+ <div class={classes} {...attrs}>
41
+ {#if title || extra}
42
+ <div class="lm-descriptions__header">
43
+ {#if title}
44
+ <div class="lm-descriptions__title">
45
+ {#if typeof title === 'string'}
46
+ {title}
47
+ {:else}
48
+ {@render title()}
49
+ {/if}
50
+ </div>
51
+ {/if}
52
+ {#if extra}
53
+ <div class="lm-descriptions__extra">
54
+ {@render extra()}
55
+ </div>
56
+ {/if}
57
+ </div>
58
+ {/if}
59
+
60
+ <div class="lm-descriptions__body">
61
+ <table class="lm-descriptions__table">
62
+ <tbody>
63
+ {#if children}
64
+ {@render children()}
65
+ {/if}
66
+ </tbody>
67
+ </table>
68
+ </div>
69
+ </div>
@@ -0,0 +1 @@
1
+ export const DESCRIPTIONS_CONTEXT_KEY = Symbol('descriptions');
@@ -0,0 +1,59 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+ import { getContext } from 'svelte'
4
+ import { DESCRIPTIONS_CONTEXT_KEY, type DescriptionsContext } from './DescriptionsContext'
5
+
6
+ interface DescriptionsItemProps {
7
+ label?: string | Snippet
8
+ span?: number
9
+ labelWidth?: string | number
10
+ align?: 'left' | 'center' | 'right'
11
+ labelAlign?: 'left' | 'center' | 'right'
12
+ children?: Snippet
13
+ class?: string
14
+ }
15
+
16
+ let { label = '', span = 1, labelWidth, align = 'left', labelAlign = 'left', children, class: cls = '', ...attrs }: DescriptionsItemProps = $props()
17
+
18
+ const descriptions = getContext<DescriptionsContext>(DESCRIPTIONS_CONTEXT_KEY)
19
+ const isBordered = $derived(descriptions?.border ?? false)
20
+
21
+ const labelStyle = $derived(labelWidth ? `width: ${typeof labelWidth === 'number' ? `${labelWidth}px` : labelWidth}; text-align: ${labelAlign}` : `text-align: ${labelAlign}`)
22
+
23
+ const contentStyle = $derived(`text-align: ${align}`)
24
+ const classes = $derived(cls ? `lm-descriptions-item ${cls}` : 'lm-descriptions-item')
25
+ </script>
26
+
27
+ {#if isBordered}
28
+ <tr class={classes} {...attrs}>
29
+ <th class="lm-descriptions-item__label" style={labelStyle}>
30
+ {#if typeof label === 'string'}
31
+ {label}
32
+ {:else if label}
33
+ {@render label()}
34
+ {/if}
35
+ </th>
36
+ <td class="lm-descriptions-item__content" colspan={span * 2 - 1} style={contentStyle}>
37
+ {#if children}
38
+ {@render children()}
39
+ {/if}
40
+ </td>
41
+ </tr>
42
+ {:else}
43
+ <tr class={classes} {...attrs}>
44
+ <td class="lm-descriptions-item__cell" colspan={span}>
45
+ <span class="lm-descriptions-item__label" style={labelStyle}>
46
+ {#if typeof label === 'string'}
47
+ {label}
48
+ {:else if label}
49
+ {@render label()}
50
+ {/if}
51
+ </span>
52
+ <span class="lm-descriptions-item__content" style={contentStyle}>
53
+ {#if children}
54
+ {@render children()}
55
+ {/if}
56
+ </span>
57
+ </td>
58
+ </tr>
59
+ {/if}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import Descriptions from './Descriptions.svelte';
2
+ import DescriptionsItem from './DescriptionsItem.svelte';
3
+ export { Descriptions, DescriptionsItem };
4
+ export default Descriptions;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@lumen-design/descriptions",
3
+ "version": "0.0.2",
4
+ "description": "Descriptions 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
+ }