@rokkit/ui 1.0.0-next.113 → 1.0.0-next.115

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/index.d.ts CHANGED
@@ -40,3 +40,6 @@ export { default as DataEditor } from "./DataEditor.svelte";
40
40
  export { default as NestedEditor } from "./NestedEditor.svelte";
41
41
  export { default as Stepper } from "./Stepper.svelte";
42
42
  export { default as ProgressDots } from "./ProgressDots.svelte";
43
+ export { default as Card } from "./Card.svelte";
44
+ export { default as Shine } from "./Shine.svelte";
45
+ export { default as Tilt } from "./Tilt.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/ui",
3
- "version": "1.0.0-next.113",
3
+ "version": "1.0.0-next.115",
4
4
  "description": "Organisms are larger, more complex building blocks that are composed of multiple molecules",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -20,7 +20,6 @@
20
20
  "dist/**/*.d.ts"
21
21
  ],
22
22
  "exports": {
23
- "./src": "./src",
24
23
  "./package.json": "./package.json",
25
24
  "./utils": "./src/lib/index.js",
26
25
  ".": {
@@ -0,0 +1,41 @@
1
+ <script>
2
+ import { Proxy } from '@rokkit/states'
3
+ let { class: classNames = '', value = $bindable(), fields, child, onClick } = $props()
4
+
5
+ const proxy = $state(new Proxy(value, fields))
6
+ const childSnippet = $derived(child ?? defaultChild)
7
+ const href = $derived(proxy.get('href'))
8
+
9
+ /**
10
+ * Handles enter key
11
+ * @param {KeyboardEvent} event
12
+ */
13
+ function handleKeyUp(event) {
14
+ if (event.key === 'Enter') onClick?.()
15
+ }
16
+ </script>
17
+
18
+ {#snippet defaultChild(/** @type {Proxy}*/ proxy)}
19
+ <icon class="flex flex-col">
20
+ <i class={proxy.get('icon')}></i>
21
+ </icon>
22
+ <h1>{proxy.get('title')}</h1>
23
+ <h2>{proxy.get('description')}</h2>
24
+ {/snippet}
25
+
26
+ {#if href}
27
+ <a {href} data-card-root class={classNames}>
28
+ {@render childSnippet(proxy)}
29
+ </a>
30
+ {:else}
31
+ <div
32
+ data-card-root
33
+ onclick={onClick}
34
+ onkeyup={handleKeyUp}
35
+ role="button"
36
+ tabindex="-1"
37
+ class={classNames}
38
+ >
39
+ {@render childSnippet(proxy)}
40
+ </div>
41
+ {/if}
@@ -12,10 +12,11 @@
12
12
 
13
13
  <span
14
14
  class="grid h-full w-4 min-w-4 grid-cols-2 grid-rows-2"
15
- class:line-empty={validatedType === 'empty'}
16
- class:line-child={validatedType === 'child'}
17
- class:line-sibling={validatedType === 'sibling'}
18
- class:line-last={validatedType === 'last'}
15
+ data-tag-tree-line
16
+ data-tag-line-empty={validatedType === 'empty' ? '' : undefined}
17
+ data-tag-line-child={validatedType === 'child' ? '' : undefined}
18
+ data-tag-line-sibling={validatedType === 'sibling' ? '' : undefined}
19
+ data-tag-line-last={validatedType === 'last' ? '' : undefined}
19
20
  >
20
21
  {#if validatedType === 'last'}
21
22
  {#if rtl}
@@ -24,7 +24,7 @@
24
24
  }
25
25
  </script>
26
26
 
27
- <Select {name} bind:value options={filtered} {...restProps} {fields} onselect={handleSelect}>
27
+ <Select {name} bind:value bind:options={filtered} {...restProps} {fields} onselect={handleSelect}>
28
28
  <span class="flex flex-grow">
29
29
  <input
30
30
  type="text"
package/src/Icon.svelte CHANGED
@@ -6,7 +6,7 @@
6
6
  * @property {any} name
7
7
  * @property {any} [state]
8
8
  * @property {string} [size]
9
- * @property {string} [role]
9
+ * @property {'img'|'button'|'checkbox'|'option'} [role]
10
10
  * @property {any} [label]
11
11
  * @property {boolean} [disabled]
12
12
  * @property {number} [tabindex]
@@ -19,6 +19,7 @@
19
19
 
20
20
  /** @type {Props} */
21
21
  let {
22
+ ref = $bindable(),
22
23
  class: classes = '',
23
24
  name,
24
25
  state = null,
@@ -37,7 +38,7 @@
37
38
  e.preventDefault()
38
39
 
39
40
  if (!disabled) {
40
- if (role === 'checkbox' || role === 'option') {
41
+ if (isCheckbox) {
41
42
  checked = !checked
42
43
  emitter?.change(checked)
43
44
  }
@@ -45,6 +46,7 @@
45
46
  }
46
47
  }
47
48
 
49
+ let isCheckbox = $derived(role === 'checkbox' || role === 'option')
48
50
  let validatedTabindex = $derived(role === 'img' || disabled ? -1 : tabindex)
49
51
  let ariaChecked = $derived(
50
52
  ['checkbox', 'option'].includes(role) ? (checked !== null ? checked : false) : null
@@ -53,18 +55,19 @@
53
55
 
54
56
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
55
57
  <rk-icon
58
+ bind:this={ref}
59
+ data-tag-icon
60
+ data-state={state}
61
+ data-tag-button={role === 'button' ? true : undefined}
62
+ data-tag-checkbox={isCheckbox ? true : undefined}
63
+ data-size={size}
64
+ data-disabled={disabled}
56
65
  class={classes}
57
- class:small={size === 'small'}
58
- class:medium={size === 'medium'}
59
- class:large={size === 'large'}
60
- class:disabled
61
66
  {role}
62
67
  aria-label={label ?? name}
63
68
  aria-checked={ariaChecked}
64
69
  onclick={handleClick}
65
70
  onkeydown={(e) => e.key === 'Enter' && e.currentTarget.click()}
66
- data-state={state}
67
- data-tag="icon"
68
71
  tabindex={validatedTabindex}
69
72
  onmouseenter={emitter.mouseenter}
70
73
  onnmouseleave={emitter.nmouseleave}
package/src/Link.svelte CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  /** @type {Props} */
14
14
  let { class: classes = '', value, mapping = new FieldMapper(), href = '#', ...rest } = $props()
15
- let url = $derived(mapping.get('url', value, href))
15
+ let url = $derived(mapping.get('href', value, href))
16
16
  let props = $derived({ ...mapping.get('props', value, {}), ...rest })
17
17
  </script>
18
18
 
@@ -32,7 +32,7 @@
32
32
  <list-editor class="flex {className}">
33
33
  <List
34
34
  bind:items={value}
35
- value={item}
35
+ bind:value={item}
36
36
  {fields}
37
37
  using={registry.components}
38
38
  on:select={handleSelect}
package/src/Select.svelte CHANGED
@@ -8,21 +8,22 @@
8
8
  // import ListItems from './ListItems.svelte'
9
9
  import Item from './Item.svelte'
10
10
 
11
- let className = ''
12
- export { className as class }
13
- export let name = null
14
- export let options = []
15
- /** @type {import('@rokkit/core').FieldMapping} */
16
- export let fields = {}
17
- export let using = {}
18
- export let value = null
19
- export let placeholder = ''
11
+ let {
12
+ class: className = '',
13
+ name = null,
14
+ options = $bindable([]),
15
+ fields,
16
+ using = {},
17
+ value = $bindable(null),
18
+ placeholder = '',
19
+ currentItem
20
+ } = $props()
20
21
 
21
- let activeIndex
22
- let open = false
23
- let offsetTop
22
+ let activeIndex = $state(-1)
23
+ let open = $state(false)
24
+ // let offsetTop
24
25
  let icons = defaultStateIcons.selector
25
- let activeItem
26
+ let activeItem = $state(null)
26
27
 
27
28
  function handleSelect() {
28
29
  open = false
@@ -51,10 +52,10 @@
51
52
  }
52
53
  }
53
54
 
54
- $: fields = { ...defaultFields, ...fields }
55
- $: using = { default: Item, ...using }
56
- $: activeIndex = options.findIndex((item) => item === value)
57
- $: offsetTop = activeItem?.offsetTop + activeItem?.clientHeight ?? 0
55
+ // $: fields = { ...defaultFields, ...fields }
56
+ // $: using = { default: Item, ...using }
57
+ // $: activeIndex = options.findIndex((item) => item === value)
58
+ let offsetTop = $derived(activeItem?.offsetTop + activeItem?.clientHeight ?? 0)
58
59
  </script>
59
60
 
60
61
  <input-select
@@ -65,27 +66,28 @@
65
66
  aria-label={name}
66
67
  use:dismissable
67
68
  use:navigable={{ horizontal: false, vertical: true }}
68
- on:focus={() => (open = true)}
69
- on:blur={() => (open = false)}
70
- on:dismiss={() => (open = false)}
71
- on:previous={handlePrevious}
72
- on:next={handleNext}
73
- on:select={handleKeySelect}
69
+ onfocus={() => (open = true)}
70
+ onblur={() => (open = false)}
71
+ ondismiss={() => (open = false)}
72
+ onprevious={handlePrevious}
73
+ onnext={handleNext}
74
+ onselect={handleKeySelect}
74
75
  >
75
- <!-- svelte-ignore a11y-click-events-have-key-events -->
76
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
76
77
  <selected-item
77
- on:click|stopPropagation={() => (open = !open)}
78
+ onclick={() => (open = !open)}
78
79
  class="flex w-full items-center"
79
80
  bind:this={activeItem}
80
81
  role="option"
81
82
  tabindex="-1"
82
83
  aria-selected={value !== null && !open}
83
84
  >
84
- <slot>
85
- <item>
86
- <svelte:component this={using.default} value={value ?? placeholder} {fields} />
87
- </item>
88
- </slot>
85
+ <item>
86
+ {#if currentItem}
87
+ {@render currentItem(value, fields)}
88
+ {/if}
89
+ <Item value={value ?? placeholder} {fields} />
90
+ </item>
89
91
  {#if open}
90
92
  <Icon name={icons.opened} label="opened" tabindex="-1" />
91
93
  {:else}
@@ -102,7 +104,14 @@
102
104
  {using}
103
105
  />
104
106
  </list> -->
105
- <List items={options} {fields} {using} bind:value on:select={handleSelect} tabindex="-1" />
107
+ <List
108
+ bind:items={options}
109
+ {fields}
110
+ {using}
111
+ bind:value
112
+ on:select={handleSelect}
113
+ tabindex="-1"
114
+ />
106
115
  </Slider>
107
116
  {/if}
108
117
  </input-select>
@@ -0,0 +1,79 @@
1
+ <script>
2
+ import { id } from '@rokkit/core'
3
+ // import { clsx } from 'clsx'
4
+
5
+ let {
6
+ color = 'var(--primary-500)',
7
+ radius = 300,
8
+ /** Depth of effect */
9
+ depth = 1,
10
+ /** Represents the height of the surface for a light filter primitive */
11
+ surfaceScale = 2,
12
+ /** The bigger the value the bigger the reflection */
13
+ specularConstant = 0.75,
14
+ /** controls the focus for the light source. The bigger the value the brighter the light */
15
+ specularExponent = 120,
16
+ children,
17
+ ...restProps
18
+ } = $props()
19
+
20
+ const filterId = id('filter')
21
+
22
+ let mouse = $state({ x: 0, y: 0 })
23
+ let wrapperBox = $state({ left: 0, top: 0 })
24
+ /** @type {HTMLDivElement|null} */
25
+ let wrapperEl = null
26
+
27
+ /**
28
+ *
29
+ * @param {PointerEvent} e
30
+ */
31
+ function onPointerMove(e) {
32
+ wrapperBox = wrapperEl?.getBoundingClientRect() ?? { left: 0, top: 0 }
33
+ mouse = { x: e.clientX, y: e.clientY }
34
+ }
35
+
36
+ function onScroll() {
37
+ wrapperBox = wrapperEl?.getBoundingClientRect() ?? { left: 0, top: 0 }
38
+ }
39
+ </script>
40
+
41
+ <svelte:window onpointermove={onPointerMove} onscroll={onScroll} />
42
+
43
+ <svg data-shine-filter class="pointer-events-none fixed inset-0">
44
+ <filter id={filterId} color-interpolation-filters="sRGB">
45
+ <feGaussianBlur in="SourceAlpha" stdDeviation={depth} />
46
+
47
+ <feSpecularLighting
48
+ result="light-source"
49
+ {surfaceScale}
50
+ {specularConstant}
51
+ {specularExponent}
52
+ lighting-color={color}
53
+ >
54
+ <fePointLight x={mouse.x - wrapperBox.left} y={mouse.y - wrapperBox.top} z={radius} />
55
+ </feSpecularLighting>
56
+
57
+ <feComposite result="reflections" in="light-source" in2="SourceAlpha" operator="in" />
58
+
59
+ <feComposite
60
+ in="SourceGraphic"
61
+ in2="reflections"
62
+ operator="arithmetic"
63
+ k1="0"
64
+ k2="1"
65
+ k3="1"
66
+ k4="0"
67
+ />
68
+ </filter>
69
+ </svg>
70
+
71
+ <div
72
+ data-shine-root
73
+ style:filter="url(#{filterId})"
74
+ {...restProps}
75
+ class="inline-block"
76
+ bind:this={wrapperEl}
77
+ >
78
+ {@render children?.()}
79
+ </div>
@@ -3,7 +3,7 @@
3
3
  import { fly, fade } from 'svelte/transition'
4
4
  import { cubicInOut } from 'svelte/easing'
5
5
 
6
- let { activeIndex = 0, columns = $bindable([]) } = $props()
6
+ let { activeIndex = $bindable(0), columns = $bindable([]) } = $props()
7
7
  let width = $state()
8
8
  let offset = $state(1)
9
9
 
@@ -20,6 +20,8 @@
20
20
  offset = -1
21
21
  }
22
22
  }
23
+
24
+ let activeColumn = $derived(columns[activeIndex])
23
25
  </script>
24
26
 
25
27
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
@@ -27,26 +29,22 @@
27
29
  use:swipeable
28
30
  onswipeleft={handlePrevious}
29
31
  onswiperight={handleNext}
30
- use:navigable
32
+ use:navigable={{ orientation: 'horizontal' }}
31
33
  onprevious={handlePrevious}
32
34
  onnext={handleNext}
33
35
  tabindex={0}
34
36
  class="relative grid h-full w-full overflow-hidden"
35
37
  bind:clientWidth={width}
36
38
  >
37
- {#each columns as column, index (index)}
38
- {#if index === activeIndex}
39
- <rk-segment
40
- class="slide absolute h-full w-full {column}"
41
- in:fly={{ x: offset * width, duration: 1000, easing: cubicInOut }}
42
- out:fade={{
43
- x: -1 * offset * width,
44
- duration: 1000,
45
- easing: cubicInOut
46
- }}
47
- >
48
- {column}
49
- </rk-segment>
50
- {/if}
51
- {/each}
39
+ <rk-segment
40
+ class="slide absolute h-full w-full"
41
+ in:fly={{ x: offset * width, duration: 1000, easing: cubicInOut }}
42
+ out:fade={{
43
+ x: -1 * offset * width,
44
+ duration: 1000,
45
+ easing: cubicInOut
46
+ }}
47
+ >
48
+ {activeColumn}
49
+ </rk-segment>
52
50
  </rk-container>
@@ -0,0 +1,66 @@
1
+ <script>
2
+ import { scaleLinear } from 'd3-scale'
3
+ import { clsx } from 'clsx'
4
+
5
+ let {
6
+ maxRotation = 10,
7
+ setBrightness = false,
8
+ perspective = 600,
9
+ class: classNames = undefined,
10
+ children
11
+ } = $props()
12
+
13
+ let width = $state(0)
14
+ let height = $state(0)
15
+
16
+ let rotateX = $state(0)
17
+ let rotateY = $state(0)
18
+ let brightness = $state(1)
19
+
20
+ let scaleX = $derived(scaleLinear().domain([0, height]).range([-maxRotation, maxRotation]))
21
+ let scaleY = $derived(scaleLinear().domain([0, width]).range([maxRotation, -maxRotation]))
22
+ let scaleBrightness = $derived(scaleLinear().domain([0, height]).range([2.0, 1.0]))
23
+
24
+ /**
25
+ *
26
+ * @param {MouseEvent} e
27
+ */
28
+ function onMouseMove(e) {
29
+ rotateY = scaleY(e.offsetX)
30
+ rotateX = scaleX(e.offsetY)
31
+
32
+ if (setBrightness) {
33
+ brightness = scaleBrightness(e.offsetY)
34
+ }
35
+ }
36
+
37
+ /**
38
+ *
39
+ */
40
+ function onMouseLeave() {
41
+ rotateX = 0
42
+ rotateY = 0
43
+ brightness = 1
44
+ }
45
+ </script>
46
+
47
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
48
+ <div
49
+ data-tilt-root
50
+ style:--perspective="{perspective}px"
51
+ style:--rotateX="{rotateX}deg"
52
+ style:--rotateY="{rotateY}deg"
53
+ style:--brightness={brightness}
54
+ class={clsx(
55
+ '[perspective:var(--perspective)]',
56
+ '[&>*]:[transform:rotateX(var(--rotateX))_rotateY(var(--rotateY))]',
57
+ '[&>*]:brightness-[var(--brightness)]',
58
+ classNames
59
+ )}
60
+ bind:clientWidth={width}
61
+ bind:clientHeight={height}
62
+ onmousemove={onMouseMove}
63
+ onmouseleave={onMouseLeave}
64
+ >
65
+ {@render children?.()}
66
+ </div>
package/src/index.js CHANGED
@@ -46,3 +46,7 @@ export { default as DataEditor } from './DataEditor.svelte'
46
46
  export { default as NestedEditor } from './NestedEditor.svelte'
47
47
  export { default as Stepper } from './Stepper.svelte'
48
48
  export { default as ProgressDots } from './ProgressDots.svelte'
49
+
50
+ export { default as Card } from './Card.svelte'
51
+ export { default as Shine } from './Shine.svelte'
52
+ export { default as Tilt } from './Tilt.svelte'