@onsvisual/svelte-components 1.0.23 → 1.0.25

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/css/main.css CHANGED
@@ -31,6 +31,9 @@ body {
31
31
  .ons-hero {
32
32
  overflow: visible;
33
33
  }
34
+ .ons-btn__inner .ons-icon {
35
+ fill: currentColor;
36
+ }
34
37
 
35
38
  /* Backfills for legacy website */
36
39
  .primary-nav__item:hover > ul,
@@ -63,3 +63,9 @@
63
63
  args={{ text: "Search", icon: "search", hideLabel: true }}
64
64
  {template}
65
65
  />
66
+
67
+ <Story
68
+ name="Custom colour button"
69
+ args={{ text: "Small button", icon: "cross", color: "#00a3a6", small: true }}
70
+ {template}
71
+ />
@@ -1,6 +1,7 @@
1
1
  <script>
2
2
  import { createEventDispatcher } from "svelte";
3
3
  import Icon from "../../decorators/Icon/Icon.svelte";
4
+ import { contrastColor, darkenColor } from "../../js/utils";
4
5
 
5
6
  const dispatch = createEventDispatcher();
6
7
 
@@ -54,6 +55,11 @@
54
55
  * @type {string|null}
55
56
  */
56
57
  export let download = null;
58
+ /**
59
+ * Set a colour for the button
60
+ * @type {string|null}
61
+ */
62
+ export let color = null;
57
63
  /**
58
64
  * Optional: Set an additional CSS class for the component
59
65
  * @type {string|null}
@@ -74,7 +80,12 @@
74
80
  on:click={(e) => dispatch("click", e)}
75
81
  aria-label={arialabel}
76
82
  >
77
- <span class="ons-btn__inner">
83
+ <span
84
+ class="ons-btn__inner"
85
+ style:background={color}
86
+ style:color={color ? contrastColor(color) : null}
87
+ style:box-shadow={color ? `0 0.1875rem 0 ${darkenColor(color)}` : null}
88
+ >
78
89
  {#if iconPosition === "before"}
79
90
  <slot name="icon">
80
91
  {#if icon}
@@ -104,7 +115,12 @@
104
115
  on:click={(e) => dispatch("click", e)}
105
116
  aria-label={arialabel}
106
117
  >
107
- <span class="ons-btn__inner">
118
+ <span
119
+ class="ons-btn__inner"
120
+ style:background={color}
121
+ style:color={color ? contrastColor(color) : null}
122
+ style:box-shadow={color ? `0 0.1875rem 0 ${darkenColor(color)}` : null}
123
+ >
108
124
  {#if iconPosition === "before"}
109
125
  <slot name="icon">
110
126
  {#if icon}
@@ -5,6 +5,7 @@ export default class Button extends SvelteComponentTyped<{
5
5
  cls?: string | null | undefined;
6
6
  small?: boolean | undefined;
7
7
  href?: string | null | undefined;
8
+ color?: string | null | undefined;
8
9
  download?: string | null | undefined;
9
10
  type?: "button" | "reset" | "sumbit" | undefined;
10
11
  variant?: "secondary" | "primary" | "ghost" | undefined;
@@ -31,6 +32,7 @@ declare const __propDef: {
31
32
  cls?: string | null | undefined;
32
33
  small?: boolean | undefined;
33
34
  href?: string | null | undefined;
35
+ color?: string | null | undefined;
34
36
  download?: string | null | undefined;
35
37
  type?: "button" | "reset" | "sumbit" | undefined;
36
38
  variant?: "secondary" | "primary" | "ghost" | undefined;
@@ -16,6 +16,7 @@ export function ascending(a: any, b: any): number;
16
16
  export function descending(a: any, b: any): number;
17
17
  export function sleep(ms?: number): Promise<any>;
18
18
  export function contrastColor(color: any): "black" | "white";
19
+ export function darkenColor(color: any, factor?: number): any;
19
20
  export function lipsum(sentences?: number, offset?: number): string;
20
21
  export function matchMedia(query: any): MediaQueryList;
21
22
  export namespace matchMedia {
package/dist/js/utils.js CHANGED
@@ -105,6 +105,16 @@ export const contrastColor = (color) => {
105
105
  return "black";
106
106
  };
107
107
 
108
+ export const darkenColor = (color, factor = 0.5) => {
109
+ if (!color || typeof color !== "string") return color;
110
+ const hsl = parse(color).hsl;
111
+ if (hsl) {
112
+ hsl[2] = hsl[2] * factor;
113
+ return `hsl(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%)`;
114
+ }
115
+ return color;
116
+ };
117
+
108
118
  export const lipsum = (sentences = 4, offset = 0) => {
109
119
  const texts = [
110
120
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",