@inglorious/ui 9.11.1 → 9.12.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/ui",
3
- "version": "9.11.1",
3
+ "version": "9.12.0",
4
4
  "description": "A design system for Inglorious Web with render-function components and customizable themes",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -57,6 +57,10 @@ export default {
57
57
  options: ["button", "submit", "reset", "menu"],
58
58
  description: "Native HTML button type attribute.",
59
59
  },
60
+ href: {
61
+ control: "text",
62
+ description: "Renders a link styled as a button.",
63
+ },
60
64
  accept: {
61
65
  control: "text",
62
66
  description: "File types the picker offers (with `onFileSelect`).",
@@ -178,6 +182,14 @@ FilePicker.args = {
178
182
  onFileSelect: () => {},
179
183
  }
180
184
 
185
+ export const Link = {}
186
+ Link.args = {
187
+ ...Default.args,
188
+ children: "Open events",
189
+ color: "primary",
190
+ href: "#events",
191
+ }
192
+
181
193
  export const CustomContent = {}
182
194
  CustomContent.args = {
183
195
  ...Default.args,
@@ -14,6 +14,7 @@ import { applyElementProps } from "../../shared/apply-element-props.js"
14
14
  * Renders a themed button for actions and form submission.
15
15
  * Supports variants, sizes, shapes, pressed state, and full-width layout.
16
16
  * With `onFileSelect`, the button also opens a file picker on click.
17
+ * With `href`, it is a link that looks like a button.
17
18
  * @example
18
19
  * // Stateless usage
19
20
  * button.render({ children: 'Click me', color: 'primary' })
@@ -21,6 +22,9 @@ import { applyElementProps } from "../../shared/apply-element-props.js"
21
22
  * // File picker
22
23
  * button.render({ children: 'Upload', accept: 'image/*', onFileSelect })
23
24
  *
25
+ * // Link
26
+ * button.render({ children: 'Open', href: '/events' })
27
+ *
24
28
  * @param {ButtonProps} props
25
29
  * @returns {TemplateResult}
26
30
  */
@@ -36,6 +40,7 @@ export function render(props) {
36
40
  isPressed = false,
37
41
  isFullWidth = false,
38
42
  buttonType = "button",
43
+ href,
39
44
  ariaLabel,
40
45
  isAriaPressed,
41
46
  className = "",
@@ -72,6 +77,18 @@ export function render(props) {
72
77
  }
73
78
  : onClick
74
79
 
80
+ if (href != null) {
81
+ return html`<a
82
+ href=${isDisabled ? nothing : href}
83
+ aria-label=${ariaLabel || nothing}
84
+ aria-disabled=${isDisabled ? "true" : nothing}
85
+ class=${classMap(classes)}
86
+ @click=${isDisabled ? nothing : onClick}
87
+ ${ref((element) => applyElementProps(element, rest))}
88
+ >${children}</a
89
+ >`
90
+ }
91
+
75
92
  return html`
76
93
  <button
77
94
  type=${buttonType}
@@ -33,9 +33,11 @@ export function render(props) {
33
33
  ...rest
34
34
  } = props
35
35
 
36
+ const isSelection = value != null || isMultiple
37
+
36
38
  const groupClasses = {
37
39
  "iw-button-group": true,
38
- "iw-button-group-selection": value != null || isMultiple,
40
+ "iw-button-group-selection": isSelection,
39
41
  [`iw-button-group-${direction}`]: true,
40
42
  "iw-button-group-attached": isAttached,
41
43
  }
@@ -86,7 +88,8 @@ export function render(props) {
86
88
  size: itemSize ?? size,
87
89
  isDisabled: isDisabled || !!itemDisabled,
88
90
  isPressed,
89
- isAriaPressed: isPressed ? true : undefined,
91
+ isAriaPressed: isSelection ? isPressed : undefined,
92
+ ariaLabel: children != null ? label : undefined,
90
93
  onClick: () => {
91
94
  if (!onChange) return
92
95
 
@@ -5,6 +5,7 @@ import type { Renderable } from "../shared/renderable"
5
5
  export interface ButtonGroupItem {
6
6
  id?: string
7
7
  value?: string
8
+ /** The button's text, or its accessible name when `children` are given */
8
9
  label: string
9
10
  children?: Renderable
10
11
  isDisabled?: boolean
@@ -21,6 +21,8 @@ export interface ButtonProps {
21
21
  isPressed?: boolean
22
22
  isFullWidth?: boolean
23
23
  buttonType?: "button" | "submit" | "reset" | "menu"
24
+ /** Renders a link styled as a button instead of a `<button>` */
25
+ href?: string
24
26
  ariaLabel?: string
25
27
  isAriaPressed?: boolean
26
28
  className?: string