lapikit 0.7.1 → 0.7.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.
@@ -9,3 +9,8 @@ export interface ElevationState {
9
9
  active?: ElevationType;
10
10
  }
11
11
  export type ElevationProps = ElevationType | ElevationState;
12
+ export interface ColorState {
13
+ base?: string;
14
+ active?: string;
15
+ }
16
+ export type ColorProps = string | ColorState;
@@ -45,6 +45,7 @@
45
45
  --kit-shape-lg: 0.875rem;
46
46
  --kit-shape-xl: 1.125rem;
47
47
  --kit-shape-full: 9999px;
48
+ --kit-animation-component: 150ms;
48
49
  }
49
50
 
50
51
  :global html {
@@ -3,7 +3,6 @@
3
3
  * Sheet component
4
4
  * @description A simple sheet component for experimentation for developers Lapikit. Please don't use it in production.
5
5
  */
6
-
7
6
  import { useComponentAttrs, useElevation } from '../../utils';
8
7
 
9
8
  let {
@@ -14,14 +13,16 @@
14
13
  's-style': sStyle,
15
14
  elevation,
16
15
  rounded,
16
+ variant = 'filled',
17
17
  active,
18
+ color,
18
19
  ...rest
19
20
  } = $props();
20
21
 
22
+ // states
21
23
  let attrs = $derived(
22
- useComponentAttrs('kit-sheet', { className, sClass, styleAttr, sStyle }, rest)
24
+ useComponentAttrs('kit-sheet', { className, sClass, styleAttr, sStyle, color, active }, rest)
23
25
  );
24
-
25
26
  let elevationState = $derived(useElevation(elevation));
26
27
  </script>
27
28
 
@@ -29,25 +30,86 @@
29
30
  class={attrs.class}
30
31
  style={attrs.style}
31
32
  data-rounded={rounded}
33
+ data-variant={variant}
32
34
  data-elevation={elevationState.base}
33
35
  data-elevation-hover={elevationState.hover}
34
36
  data-elevation-active={elevationState.active}
35
37
  data-active={active}
36
38
  {...attrs.rest}
37
39
  >
38
- {@render children()}
40
+ {@render children?.()}
39
41
  </div>
40
42
 
41
43
  <style>.kit-sheet {
44
+ --kit-sheet-color: initial;
45
+ --kit-sheet-on-color: initial;
46
+ --kit-sheet-active-fg: initial;
47
+ --kit-sheet-active-shade: initial;
48
+ --kit-sheet-bg: var(--kit-sheet-color, var(--kit-color-surface-1));
49
+ --kit-sheet-fg: var(--kit-sheet-on-color, var(--kit-sheet-contrast, var(--kit-color-text)));
50
+ --kit-sheet-ink: var(--kit-sheet-color, var(--kit-color-text));
51
+ --kit-sheet-hover: color-mix(in oklab, var(--kit-sheet-bg), var(--kit-sheet-fg) 8%);
52
+ --kit-sheet-pressed: color-mix(in oklab, var(--kit-sheet-bg), var(--kit-sheet-fg) 14%);
53
+ --kit-sheet-soft: color-mix(in oklab, var(--kit-sheet-bg) 16%, transparent);
54
+ --kit-sheet-border: color-mix(in oklab, var(--kit-sheet-bg), var(--kit-sheet-fg) 20%);
55
+ --kit-sheet-active: color-mix(
56
+ in oklab,
57
+ var(--kit-sheet-color),
58
+ var(--kit-sheet-fg) var(--kit-sheet-active-shade, 14%)
59
+ );
60
+ }
61
+ @supports (color: color(from red srgb-linear r g b)) {
62
+ .kit-sheet {
63
+ --kit-sheet-contrast: color(from var(--kit-sheet-color) srgb-linear clamp(0, (0.1791 - (0.2126 * r + 0.7152 * g + 0.0722 * b)) * 100000, 1) clamp(0, (0.1791 - (0.2126 * r + 0.7152 * g + 0.0722 * b)) * 100000, 1) clamp(0, (0.1791 - (0.2126 * r + 0.7152 * g + 0.0722 * b)) * 100000, 1)/1);
64
+ }
65
+ }
66
+ .kit-sheet {
42
67
  display: flex;
43
- background-color: var(--kit-color-surface-1);
44
- color: var(--kit-color-text);
68
+ background-color: var(--kit-sheet-bg);
69
+ color: var(--kit-sheet-fg);
45
70
  border-radius: var(--kit-sheet-radius);
71
+ transition-property: background-color, color, border-color, box-shadow;
72
+ transition-duration: var(--kit-animation-component);
73
+ transition-timing-function: ease;
74
+ }
75
+ @media (prefers-reduced-motion: reduce) {
76
+ .kit-sheet {
77
+ transition: none;
78
+ }
79
+ }
80
+
81
+ .kit-sheet[data-variant=tonal] {
82
+ --kit-sheet-bg: color-mix(in oklab, var(--kit-sheet-ink) 16%, transparent);
83
+ --kit-sheet-fg: var(--kit-sheet-ink);
84
+ --kit-sheet-border: transparent;
85
+ --kit-sheet-active: color-mix(in oklab, var(--kit-sheet-ink) 28%, transparent);
86
+ --kit-sheet-active-fg: var(--kit-sheet-ink);
87
+ }
88
+
89
+ .kit-sheet[data-variant=outline] {
90
+ --kit-sheet-bg: transparent;
91
+ --kit-sheet-fg: var(--kit-sheet-ink);
92
+ --kit-sheet-border: var(--kit-sheet-color, var(--kit-color-border));
93
+ --kit-sheet-active: color-mix(in oklab, var(--kit-sheet-ink) 14%, transparent);
94
+ --kit-sheet-active-fg: var(--kit-sheet-ink);
95
+ border: 1px solid var(--kit-sheet-border);
96
+ }
97
+
98
+ .kit-sheet[data-variant=surface] {
99
+ --kit-sheet-bg: color-mix(in oklab, var(--kit-sheet-ink) 8%, transparent);
100
+ --kit-sheet-fg: var(--kit-sheet-ink);
101
+ --kit-sheet-border: color-mix(in oklab, var(--kit-sheet-ink) 35%, transparent);
102
+ --kit-sheet-active: color-mix(in oklab, var(--kit-sheet-ink) 18%, transparent);
103
+ --kit-sheet-active-fg: var(--kit-sheet-ink);
104
+ border: 1px solid var(--kit-sheet-border);
46
105
  }
47
106
 
48
107
  .kit-sheet[data-active=true] {
49
- background: var(--kit-color-accent);
50
- color: var(--kit-on-accent);
108
+ --kit-sheet-bg: var(--kit-sheet-active, var(--kit-color-accent));
109
+ --kit-sheet-fg: var(
110
+ --kit-sheet-active-fg,
111
+ var(--kit-sheet-on-color, var(--kit-sheet-contrast, var(--kit-color-on-accent)))
112
+ );
51
113
  }
52
114
 
53
115
  /**
@@ -4,7 +4,9 @@ declare const Sheet: import("svelte").Component<{
4
4
  children: any;
5
5
  elevation: any;
6
6
  rounded: any;
7
+ variant?: string;
7
8
  active: any;
9
+ color: any;
8
10
  } & Record<string, any>, {}, "">;
9
11
  type Sheet = ReturnType<typeof Sheet>;
10
12
  export default Sheet;
@@ -0,0 +1,4 @@
1
+ import type { ColorProps } from '../@types';
2
+ export declare function resolveColor(color: string | null | undefined): string | undefined;
3
+ export declare function resolveOnColor(color: string | null | undefined): string | undefined;
4
+ export declare function colorStyle(name: string, color: ColorProps | null | undefined, active?: boolean): string;
@@ -0,0 +1,40 @@
1
+ import { DEV } from 'esm-env';
2
+ const paletteName = /^[a-zA-Z][\w-]*$/;
3
+ const unsafe = /[;{}]/;
4
+ function clean(color) {
5
+ const value = color?.trim();
6
+ if (!value)
7
+ return undefined;
8
+ if (unsafe.test(value)) {
9
+ if (DEV)
10
+ console.warn(`[lapikit] color "${value}" is ignored: it cannot hold ; { or }`);
11
+ return undefined;
12
+ }
13
+ return value;
14
+ }
15
+ export function resolveColor(color) {
16
+ const value = clean(color);
17
+ if (!value)
18
+ return undefined;
19
+ return paletteName.test(value) ? `var(--kit-color-${value}, ${value})` : value;
20
+ }
21
+ export function resolveOnColor(color) {
22
+ const value = clean(color);
23
+ if (!value || !paletteName.test(value))
24
+ return undefined;
25
+ return `var(--kit-color-on-${value})`;
26
+ }
27
+ export function colorStyle(name, color, active = false) {
28
+ const exact = active && typeof color === 'object' && !!clean(color?.active);
29
+ const current = typeof color === 'object' ? (exact ? color?.active : color?.base) : color;
30
+ const value = resolveColor(current);
31
+ if (!name || !value)
32
+ return '';
33
+ const styles = [`--${name}-color: ${value}`];
34
+ const onColor = resolveOnColor(current);
35
+ if (onColor)
36
+ styles.push(`--${name}-on-color: ${onColor}`);
37
+ if (exact)
38
+ styles.push(`--${name}-active-shade: 0%`);
39
+ return styles.join('; ');
40
+ }
@@ -1,4 +1,4 @@
1
- import type { ComponentAttrs, ElevationProps, ElevationState, PropValue, SStyleProp, useClassNameProps, useStylesProps } from '../@types';
1
+ import type { ColorProps, ComponentAttrs, ElevationProps, ElevationState, PropValue, SStyleProp, useClassNameProps, useStylesProps } from '../@types';
2
2
  import type { ClassValue } from 'svelte/elements';
3
3
  /**
4
4
  * The classes of the s-class_xxx directives (class:xxx on a kit tag):
@@ -42,13 +42,19 @@ export declare function useElevation(elevation?: ElevationProps | null): Elevati
42
42
  * ({ active: isActive } -> active). The s-class_xxx directives (class:xxx on a kit tag) keep their
43
43
  * rule: class:gap={4} -> gap-4.
44
44
  *
45
- * @param baseClass - The class of the component ('kit-btn-v2'), '' for none.
46
- * @param props - The class, s-class, style and s-style props of the component.
45
+ * @param baseClass - The class of the component ('kit-btn'), '' for none.
46
+ * The color prop gives the --{baseClass}-color / --{baseClass}-on-color variables, read by the
47
+ * color mixin; they come before the style, so the style attribute still wins.
48
+ * With { base, active }, active picks the color of the active state.
49
+ *
50
+ * @param props - The class, s-class, style, s-style, color and active props of the component.
47
51
  * @param rest - The rest of the props: the s-class_xxx / s-style_xxx directives are taken out of it.
48
52
  */
49
- export declare function useComponentAttrs(baseClass: string, { className, sClass, styleAttr, sStyle }: {
53
+ export declare function useComponentAttrs(baseClass: string, { className, sClass, styleAttr, sStyle, color, active }: {
50
54
  className?: ClassValue;
51
55
  sClass?: ClassValue;
52
56
  styleAttr?: string;
53
57
  sStyle?: SStyleProp;
58
+ color?: ColorProps | null;
59
+ active?: boolean;
54
60
  }, rest: Record<string, unknown>): ComponentAttrs;
@@ -1,5 +1,6 @@
1
1
  import { DEV } from 'esm-env';
2
2
  import { makeComponentProps } from '../html-mapped';
3
+ import { colorStyle } from './color.js';
3
4
  const endsWithSeparator = /[^a-zA-Z0-9]$/;
4
5
  const startsWithSeparator = /^[^a-zA-Z0-9]/;
5
6
  const whitespace = /\s/;
@@ -224,15 +225,21 @@ export function useElevation(elevation) {
224
225
  * ({ active: isActive } -> active). The s-class_xxx directives (class:xxx on a kit tag) keep their
225
226
  * rule: class:gap={4} -> gap-4.
226
227
  *
227
- * @param baseClass - The class of the component ('kit-btn-v2'), '' for none.
228
- * @param props - The class, s-class, style and s-style props of the component.
228
+ * @param baseClass - The class of the component ('kit-btn'), '' for none.
229
+ * The color prop gives the --{baseClass}-color / --{baseClass}-on-color variables, read by the
230
+ * color mixin; they come before the style, so the style attribute still wins.
231
+ * With { base, active }, active picks the color of the active state.
232
+ *
233
+ * @param props - The class, s-class, style, s-style, color and active props of the component.
229
234
  * @param rest - The rest of the props: the s-class_xxx / s-style_xxx directives are taken out of it.
230
235
  */
231
- export function useComponentAttrs(baseClass, { className, sClass, styleAttr, sStyle }, rest) {
236
+ export function useComponentAttrs(baseClass, { className, sClass, styleAttr, sStyle, color, active }, rest) {
232
237
  const { classProps, styleProps, restProps } = makeComponentProps(rest);
233
238
  return {
234
239
  class: [baseClass, sClass, directiveClasses(classProps), className],
235
- style: useStyles({ styleAttr, sStyle, styleProps }),
240
+ style: [colorStyle(baseClass, color, active), useStyles({ styleAttr, sStyle, styleProps })]
241
+ .filter(Boolean)
242
+ .join('; '),
236
243
  rest: restProps
237
244
  };
238
245
  }
@@ -1,2 +1,3 @@
1
1
  export * from './components.js';
2
2
  export * from './outside.js';
3
+ export * from './color.js';
@@ -1,2 +1,3 @@
1
1
  export * from './components.js';
2
2
  export * from './outside.js';
3
+ export * from './color.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapikit",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"