@14ch/svelte-ui 0.0.51 → 0.0.53

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.
@@ -11,7 +11,7 @@
11
11
  TouchHandler,
12
12
  PointerHandler
13
13
  } from '../types/callbackHandlers';
14
- import type { ButtonVariant, ButtonSize } from '../types/propOptions';
14
+ import type { ButtonVariant, ButtonSize, IconPosition } from '../types/propOptions';
15
15
  import Icon from './Icon.svelte';
16
16
  import LoadingSpinner from './LoadingSpinner.svelte';
17
17
  import { getStyleFromNumber } from '../utils/style';
@@ -46,6 +46,8 @@
46
46
  // アイコン関連
47
47
  /** Material Symbols icon name. */
48
48
  icon?: string;
49
+ /** Icon position relative to the label. @default 'left' */
50
+ iconPosition?: IconPosition;
49
51
  iconFilled?: boolean;
50
52
  iconWeight?: IconWeight;
51
53
  iconGrade?: IconGrade;
@@ -121,6 +123,7 @@
121
123
 
122
124
  // アイコン関連
123
125
  icon = '',
126
+ iconPosition = 'left',
124
127
  iconFilled = false,
125
128
  iconWeight = 300,
126
129
  iconGrade = 0,
@@ -368,19 +371,23 @@
368
371
  data-testid="button"
369
372
  {...restProps}
370
373
  >
374
+ {#snippet iconContent()}
375
+ <Icon
376
+ filled={iconFilled}
377
+ weight={iconWeight}
378
+ grade={iconGrade}
379
+ opticalSize={iconOpticalSize}
380
+ variant={iconVariant}>{icon}</Icon
381
+ >
382
+ {/snippet}
383
+
371
384
  {#if loading}
372
385
  <div class="button__loading">
373
386
  <LoadingSpinner size={18} strokeWidth={2} color="currentColor" />
374
387
  </div>
375
- {:else if icon}
376
- <div class="button__icon">
377
- <Icon
378
- filled={iconFilled}
379
- weight={iconWeight}
380
- grade={iconGrade}
381
- opticalSize={iconOpticalSize}
382
- variant={iconVariant}>{icon}</Icon
383
- >
388
+ {:else if icon && iconPosition === 'left'}
389
+ <div class="button__icon button__icon--left">
390
+ {@render iconContent()}
384
391
  </div>
385
392
  {/if}
386
393
 
@@ -388,6 +395,12 @@
388
395
  {@render children()}
389
396
  </div>
390
397
 
398
+ {#if icon && iconPosition === 'right' && !loading}
399
+ <div class="button__icon button__icon--right">
400
+ {@render iconContent()}
401
+ </div>
402
+ {/if}
403
+
391
404
  {#if popup && !loading}
392
405
  <div class="button__popup-icon">
393
406
  <Icon>arrow_drop_down</Icon>
@@ -519,12 +532,24 @@
519
532
  }
520
533
 
521
534
  .button__icon {
522
- margin: -12px 0 -12px -4px;
535
+ margin: -12px 0;
523
536
  display: flex;
524
537
  align-items: center;
525
538
  justify-content: center;
526
539
  }
527
540
 
541
+ .button__icon--left {
542
+ margin-left: -4px;
543
+ }
544
+
545
+ .button__icon--right {
546
+ margin-right: -4px;
547
+ }
548
+
549
+ .button--align-left .button__icon--right {
550
+ margin-left: auto;
551
+ }
552
+
528
553
  .button__label {
529
554
  display: block;
530
555
  width: auto;
@@ -562,10 +587,14 @@
562
587
  }
563
588
 
564
589
  /* Size-specific adjustments */
565
- .button--small .button__icon {
590
+ .button--small .button__icon--left {
566
591
  margin-left: -2px;
567
592
  }
568
593
 
594
+ .button--small .button__icon--right {
595
+ margin-right: -2px;
596
+ }
597
+
569
598
  .button--small .button__popup-icon {
570
599
  margin-right: -2px;
571
600
  }
@@ -575,10 +604,14 @@
575
604
  margin-right: -2px;
576
605
  }
577
606
 
578
- .button--large .button__icon {
607
+ .button--large .button__icon--left {
579
608
  margin-left: -6px;
580
609
  }
581
610
 
611
+ .button--large .button__icon--right {
612
+ margin-right: -6px;
613
+ }
614
+
582
615
  .button--large .button__popup-icon {
583
616
  margin-right: -6px;
584
617
  }
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLButtonAttributes } from 'svelte/elements';
3
3
  import type { IconVariant, IconWeight, IconGrade, IconOpticalSize } from '../types/icon';
4
4
  import type { FocusHandler, KeyboardHandler, MouseHandler, TouchHandler, PointerHandler } from '../types/callbackHandlers';
5
- import type { ButtonVariant, ButtonSize } from '../types/propOptions';
5
+ import type { ButtonVariant, ButtonSize, IconPosition } from '../types/propOptions';
6
6
  export type ButtonProps = {
7
7
  children: Snippet;
8
8
  /** @default 'button' */
@@ -23,6 +23,8 @@ export type ButtonProps = {
23
23
  popup?: boolean;
24
24
  /** Material Symbols icon name. */
25
25
  icon?: string;
26
+ /** Icon position relative to the label. @default 'left' */
27
+ iconPosition?: IconPosition;
26
28
  iconFilled?: boolean;
27
29
  iconWeight?: IconWeight;
28
30
  iconGrade?: IconGrade;
@@ -238,7 +238,7 @@
238
238
 
239
239
  .dialog--scrollable .dialog__header {
240
240
  margin-bottom: 0;
241
- border-bottom: solid var(--svelte-ui-border-width, 1px) var(--svelte-ui-border-weak-color);
241
+ border-bottom: solid 1px var(--svelte-ui-border-color);
242
242
  }
243
243
 
244
244
  .dialog--scrollable .dialog__body {
@@ -248,5 +248,5 @@
248
248
  }
249
249
 
250
250
  .dialog--scrollable .dialog__footer {
251
- border-top: solid var(--svelte-ui-border-width, 1px) var(--svelte-ui-border-weak-color);
251
+ border-top: solid 1px var(--svelte-ui-border-color);
252
252
  }</style>
@@ -11,7 +11,7 @@
11
11
  TouchHandler,
12
12
  PointerHandler
13
13
  } from '../types/callbackHandlers';
14
- import type { ButtonVariant, FabPosition } from '../types/propOptions';
14
+ import type { ButtonVariant, FabPosition, IconPosition } from '../types/propOptions';
15
15
  import Icon from './Icon.svelte';
16
16
  import LoadingSpinner from './LoadingSpinner.svelte';
17
17
  import { getStyleFromNumber } from '../utils/style';
@@ -29,6 +29,8 @@
29
29
  loading?: boolean;
30
30
  /** Material Symbols icon name. */
31
31
  icon?: string;
32
+ /** Icon position relative to the label. @default 'left' */
33
+ iconPosition?: IconPosition;
32
34
  iconFilled?: boolean;
33
35
  iconWeight?: IconWeight;
34
36
  iconGrade?: IconGrade;
@@ -106,6 +108,7 @@
106
108
 
107
109
  // アイコン関連
108
110
  icon = '',
111
+ iconPosition = 'left',
109
112
  iconFilled = false,
110
113
  iconWeight = 300,
111
114
  iconGrade = 0,
@@ -348,20 +351,24 @@
348
351
  aria-busy={loading ? 'true' : undefined}
349
352
  data-testid="fab"
350
353
  >
354
+ {#snippet iconContent()}
355
+ <Icon
356
+ filled={iconFilled}
357
+ weight={iconWeight}
358
+ grade={iconGrade}
359
+ opticalSize={iconOpticalSize}
360
+ variant={iconVariant}
361
+ size={24}>{icon}</Icon
362
+ >
363
+ {/snippet}
364
+
351
365
  {#if loading}
352
366
  <div class="fab__loading">
353
367
  <LoadingSpinner size={24} strokeWidth={2} color="currentColor" />
354
368
  </div>
355
- {:else if icon}
356
- <div class="fab__icon">
357
- <Icon
358
- filled={iconFilled}
359
- weight={iconWeight}
360
- grade={iconGrade}
361
- opticalSize={iconOpticalSize}
362
- variant={iconVariant}
363
- size={24}>{icon}</Icon
364
- >
369
+ {:else if icon && iconPosition === 'left'}
370
+ <div class="fab__icon fab__icon--left">
371
+ {@render iconContent()}
365
372
  </div>
366
373
  {/if}
367
374
 
@@ -370,6 +377,12 @@
370
377
  {@render children()}
371
378
  </div>
372
379
  {/if}
380
+
381
+ {#if icon && iconPosition === 'right' && !loading}
382
+ <div class="fab__icon fab__icon--right">
383
+ {@render iconContent()}
384
+ </div>
385
+ {/if}
373
386
  </button>
374
387
 
375
388
  <style>.fab {
@@ -470,12 +483,17 @@
470
483
  transition-duration: 0.01s;
471
484
  }
472
485
  .fab .fab__icon {
473
- margin: 0 8px 0 -8px;
474
486
  user-select: none;
475
487
  display: flex;
476
488
  align-items: center;
477
489
  justify-content: center;
478
490
  }
491
+ .fab .fab__icon--left {
492
+ margin: 0 8px 0 -8px;
493
+ }
494
+ .fab .fab__icon--right {
495
+ margin: 0 -8px 0 8px;
496
+ }
479
497
  .fab .fab__loading {
480
498
  position: absolute;
481
499
  top: 50%;
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLButtonAttributes } from 'svelte/elements';
3
3
  import type { IconVariant, IconWeight, IconGrade, IconOpticalSize } from '../types/icon';
4
4
  import type { FocusHandler, KeyboardHandler, MouseHandler, TouchHandler, PointerHandler } from '../types/callbackHandlers';
5
- import type { ButtonVariant, FabPosition } from '../types/propOptions';
5
+ import type { ButtonVariant, FabPosition, IconPosition } from '../types/propOptions';
6
6
  export type FabProps = {
7
7
  children?: Snippet;
8
8
  /** @default 'button' */
@@ -13,6 +13,8 @@ export type FabProps = {
13
13
  loading?: boolean;
14
14
  /** Material Symbols icon name. */
15
15
  icon?: string;
16
+ /** Icon position relative to the label. @default 'left' */
17
+ iconPosition?: IconPosition;
16
18
  iconFilled?: boolean;
17
19
  iconWeight?: IconWeight;
18
20
  iconGrade?: IconGrade;
@@ -16,6 +16,8 @@
16
16
  // 基本プロパティ
17
17
  /** `{ label, href, icon?, children?, disabled? }[]` */
18
18
  navItems?: MenuItem[];
19
+ /** `navItems` のエイリアス。両方指定された場合は `navItems` が優先。 */
20
+ items?: MenuItem[];
19
21
  /** Layout variant. @default 'horizontal' */
20
22
  variant?: NavVariant;
21
23
  /** Prepended to each item's href for active-state matching. */
@@ -65,7 +67,8 @@
65
67
 
66
68
  let {
67
69
  // 基本プロパティ
68
- navItems = [],
70
+ navItems: navItemsProp,
71
+ items: itemsAlias,
69
72
  variant = 'horizontal',
70
73
  pathPrefix = '',
71
74
  customPathMatcher,
@@ -103,6 +106,9 @@
103
106
  ariaLabelledby
104
107
  }: NavProps = $props();
105
108
 
109
+ // navItems(正式名)を優先し、items(エイリアス)へフォールバック
110
+ const navItems = $derived<MenuItem[]>(navItemsProp ?? itemsAlias ?? []);
111
+
106
112
  let resolvedCurrentPath = $state('');
107
113
  let navEl: HTMLElement | undefined = $state();
108
114
  let subBarEl: HTMLElement | undefined = $state();
@@ -5,6 +5,8 @@ import type { IconVariant, IconWeight, IconGrade, IconOpticalSize } from '../typ
5
5
  export type NavProps = {
6
6
  /** `{ label, href, icon?, children?, disabled? }[]` */
7
7
  navItems?: MenuItem[];
8
+ /** `navItems` のエイリアス。両方指定された場合は `navItems` が優先。 */
9
+ items?: MenuItem[];
8
10
  /** Layout variant. @default 'horizontal' */
9
11
  variant?: NavVariant;
10
12
  /** Prepended to each item's href for active-state matching. */
@@ -21,12 +21,17 @@
21
21
  // =========================================================================
22
22
  export type StepNavProps = {
23
23
  // 基本プロパティ
24
- /** `{ label, value?, href?, description?, icon?, error?, disabled? }[]` */
25
- items: StepItem[];
24
+ /** ステップ配列(正式名称)。`{ label, value?, href?, description?, icon?, error?, disabled? }[]` */
25
+ stepItems?: StepItem[];
26
+ /** `stepItems` のエイリアス。両方指定された場合は `stepItems` が優先。 */
27
+ items?: StepItem[];
26
28
  /** 表示中ステップの値(インページ方式)。`bind:value` 対応。`item.value` 省略時は配列 index の文字列('0','1',...)が暗黙の値になる。 */
27
29
  value?: string;
28
- /** 到達済みの最遠ステップの 0 始まりインデックス(進捗軸)。未指定時は表示中ステップ位置。 */
29
- progress?: number;
30
+ /**
31
+ * 到達済みの最遠ステップ(進捗軸)。未指定時は表示中ステップ位置。
32
+ * 数値なら 0 始まりのインデックス、文字列ならアイテムのユニークキー(`value`。省略時は配列 index の文字列)で指定する。URL方式でも `value` をキーに使う。
33
+ */
34
+ progress?: number | string;
30
35
 
31
36
  // URL 方式(href 使用時)
32
37
  /** 各 href のアクティブ判定に前置するパス。 */
@@ -80,7 +85,8 @@
80
85
 
81
86
  let {
82
87
  // 基本プロパティ
83
- items = [],
88
+ stepItems,
89
+ items: itemsAlias,
84
90
  value = $bindable(''),
85
91
  progress,
86
92
 
@@ -141,6 +147,9 @@
141
147
  // =========================================================================
142
148
  // Derived state
143
149
  // =========================================================================
150
+ // stepItems(正式名)を優先し、items(エイリアス)へフォールバック
151
+ const items = $derived<StepItem[]>(stepItems ?? itemsAlias ?? []);
152
+
144
153
  const isLinkMode = $derived(items.some((item) => item.href != null));
145
154
 
146
155
  const activeIndex = $derived.by(() => {
@@ -162,7 +171,12 @@
162
171
  return items.findIndex((item, index) => (item.value ?? String(index)) === value);
163
172
  });
164
173
 
165
- const progressIndex = $derived(progress ?? activeIndex);
174
+ // progress を数値インデックスへ解決する。文字列ならアイテムのユニークキー(value)で一致判定。未指定なら表示中位置。
175
+ const progressIndex = $derived.by(() => {
176
+ if (progress == null) return activeIndex;
177
+ if (typeof progress === 'number') return progress;
178
+ return items.findIndex((item, index) => (item.value ?? String(index)) === progress);
179
+ });
166
180
 
167
181
  const resolvedIconSize = $derived(
168
182
  iconOpticalSize || (size === 'small' ? 16 : size === 'large' ? 24 : 20)
@@ -3,12 +3,17 @@ import type { ComponentSize, StepNavOrientation } from '../types/propOptions';
3
3
  import type { IconVariant, IconWeight, IconGrade, IconOpticalSize } from '../types/icon';
4
4
  import type { MouseHandler, FocusHandler, KeyboardHandler, BivariantValueHandler } from '../types/callbackHandlers';
5
5
  export type StepNavProps = {
6
- /** `{ label, value?, href?, description?, icon?, error?, disabled? }[]` */
7
- items: StepItem[];
6
+ /** ステップ配列(正式名称)。`{ label, value?, href?, description?, icon?, error?, disabled? }[]` */
7
+ stepItems?: StepItem[];
8
+ /** `stepItems` のエイリアス。両方指定された場合は `stepItems` が優先。 */
9
+ items?: StepItem[];
8
10
  /** 表示中ステップの値(インページ方式)。`bind:value` 対応。`item.value` 省略時は配列 index の文字列('0','1',...)が暗黙の値になる。 */
9
11
  value?: string;
10
- /** 到達済みの最遠ステップの 0 始まりインデックス(進捗軸)。未指定時は表示中ステップ位置。 */
11
- progress?: number;
12
+ /**
13
+ * 到達済みの最遠ステップ(進捗軸)。未指定時は表示中ステップ位置。
14
+ * 数値なら 0 始まりのインデックス、文字列ならアイテムのユニークキー(`value`。省略時は配列 index の文字列)で指定する。URL方式でも `value` をキーに使う。
15
+ */
16
+ progress?: number | string;
12
17
  /** 各 href のアクティブ判定に前置するパス。 */
13
18
  pathPrefix?: string;
14
19
  /** アクティブ判定をカスタムする関数。 */
@@ -12,6 +12,8 @@
12
12
  // 基本プロパティ
13
13
  /** `{ label, href, icon?, disabled? }[]` */
14
14
  tabItems?: MenuItem[];
15
+ /** `tabItems` のエイリアス。両方指定された場合は `tabItems` が優先。 */
16
+ items?: MenuItem[];
15
17
  /** Prepended to each item's href for active-state matching. */
16
18
  pathPrefix?: string;
17
19
  /** Custom function to determine if an item is active. */
@@ -52,7 +54,8 @@
52
54
 
53
55
  let {
54
56
  // 基本プロパティ
55
- tabItems = [],
57
+ tabItems: tabItemsProp,
58
+ items: itemsAlias,
56
59
  pathPrefix = '',
57
60
  customPathMatcher,
58
61
  currentPath,
@@ -80,6 +83,9 @@
80
83
  ariaLabel = 'Tabs',
81
84
  ariaLabelledby
82
85
  }: TabProps = $props();
86
+
87
+ // tabItems(正式名)を優先し、items(エイリアス)へフォールバック
88
+ const tabItems = $derived<MenuItem[]>(tabItemsProp ?? itemsAlias ?? []);
83
89
  </script>
84
90
 
85
91
  <div class="tab" data-testid="tab">
@@ -3,6 +3,8 @@ import type { IconVariant, IconWeight, IconGrade, IconOpticalSize } from '../typ
3
3
  export type TabProps = {
4
4
  /** `{ label, href, icon?, disabled? }[]` */
5
5
  tabItems?: MenuItem[];
6
+ /** `tabItems` のエイリアス。両方指定された場合は `tabItems` が優先。 */
7
+ items?: MenuItem[];
6
8
  /** Prepended to each item's href for active-state matching. */
7
9
  pathPrefix?: string;
8
10
  /** Custom function to determine if an item is active. */
package/dist/index.d.ts CHANGED
@@ -85,7 +85,7 @@ export type { NavProps } from './components/Nav.svelte';
85
85
  export type { NavItemProps, NavItemSelectedVariant } from './components/NavItem.svelte';
86
86
  export type { TabProps } from './components/Tab.svelte';
87
87
  export type { TextareaProps } from './components/Textarea.svelte';
88
- export type { PopupPosition, SnackbarPosition, FabPosition, ButtonVariant, ButtonSize, ComponentSize, SnackbarType, SnackbarVariant, BadgeVariant, DatepickerMode, FocusStyle, NavVariant, ChildrenVariant, StepNavOrientation } from './types/propOptions';
88
+ export type { PopupPosition, SnackbarPosition, FabPosition, ButtonVariant, ButtonSize, IconPosition, ComponentSize, SnackbarType, SnackbarVariant, BadgeVariant, DatepickerMode, FocusStyle, NavVariant, ChildrenVariant, StepNavOrientation } from './types/propOptions';
89
89
  export type { MenuItem } from './types/menuItem';
90
90
  export type { StepItem } from './types/stepItem';
91
91
  export type { SegmentedControlItem } from './types/segmentedControlItem';
@@ -22,6 +22,11 @@ export type FabPosition = 'left' | 'center' | 'right';
22
22
  * Used by Button, IconButton, Fab components
23
23
  */
24
24
  export type ButtonVariant = 'ghost' | 'filled' | 'outlined' | 'glass';
25
+ /**
26
+ * Icon position type (left/right)
27
+ * Used by Button, Fab components
28
+ */
29
+ export type IconPosition = 'left' | 'right';
25
30
  /**
26
31
  * Common component size type
27
32
  * Used by Button, Checkbox, CheckboxGroup, Radio, RadioGroup, SegmentedControl, Switch
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@14ch/svelte-ui",
3
3
  "description": "Modern Svelte UI components library with TypeScript support",
4
4
  "private": false,
5
- "version": "0.0.51",
5
+ "version": "0.0.53",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",