@dnd-mapp/shared-ui 0.1.0-rc.1 → 1.0.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/README.md +12 -0
- package/fesm2022/dnd-mapp-shared-ui.mjs +33 -10
- package/fesm2022/dnd-mapp-shared-ui.mjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/button/README.md +117 -0
- package/types/dnd-mapp-shared-ui.d.ts +20 -5
package/README.md
CHANGED
|
@@ -15,6 +15,18 @@ The official Angular component library for the **D&D Mapp** platform. This libra
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
+
## 🧱 UI Components
|
|
19
|
+
|
|
20
|
+
A collection of high-performance, accessible components. Click on a component name to view its specific documentation, API, and usage examples.
|
|
21
|
+
|
|
22
|
+
| Component | Status | Description |
|
|
23
|
+
|----------------------------------------|--------|---------------------------------------------------------------------|
|
|
24
|
+
| **[Button](src/lib/button/README.md)** | ✅ | Primary action component with support for variants (base, primary). |
|
|
25
|
+
|
|
26
|
+
> **[!TIP]** ✅ Ready for Production | 🚧 In Development | 🧪 Experimental
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
18
30
|
## 🚀 Installation
|
|
19
31
|
|
|
20
32
|
Install the package via pnpm (recommended) or your preferred package manager:
|
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { input, computed, Component } from '@angular/core';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const ButtonColors = {
|
|
5
|
+
PRIMARY: 'primary',
|
|
6
|
+
BASE: 'base',
|
|
7
|
+
};
|
|
8
|
+
const DEFAULT_BUTTON_COLOR = ButtonColors.BASE;
|
|
9
|
+
function buttonColorAttribute(value) {
|
|
10
|
+
return Object.values(ButtonColors).find((color) => value === color) ?? DEFAULT_BUTTON_COLOR;
|
|
7
11
|
}
|
|
8
|
-
|
|
12
|
+
|
|
13
|
+
class ButtonComponent {
|
|
14
|
+
color = input(DEFAULT_BUTTON_COLOR, { ...(ngDevMode ? { debugName: "color" } : {}), transform: buttonColorAttribute, alias: 'dma-button' });
|
|
15
|
+
isBase = computed(() => this.color() === ButtonColors.BASE, ...(ngDevMode ? [{ debugName: "isBase" }] : []));
|
|
16
|
+
isPrimary = computed(() => this.color() === ButtonColors.PRIMARY, ...(ngDevMode ? [{ debugName: "isPrimary" }] : []));
|
|
17
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: ButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
18
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.1.4", type: ButtonComponent, isStandalone: true, selector: "button[dma-button]", inputs: { color: { classPropertyName: "color", publicName: "dma-button", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "'font-semibold cursor-pointer py-2 px-4 rounded-md'", "class.text-neutral-900": "isBase()", "class.text-neutral-100": "isPrimary()", "class.bg-neutral-100": "isBase()", "class.hover:bg-neutral-200": "isBase()", "class.active:bg-neutral-300": "isBase()", "class.bg-blue-400": "isPrimary()", "class.hover:bg-blue-500": "isPrimary()", "class.active:bg-blue-600": "isPrimary()" } }, ngImport: i0, template: `<ng-content />`, isInline: true });
|
|
19
|
+
}
|
|
20
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.4", ngImport: i0, type: ButtonComponent, decorators: [{
|
|
9
21
|
type: Component,
|
|
10
22
|
args: [{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
// eslint-disable-next-line @angular-eslint/component-selector
|
|
24
|
+
selector: 'button[dma-button]',
|
|
25
|
+
template: `<ng-content />`,
|
|
26
|
+
host: {
|
|
27
|
+
'[class]': `'font-semibold cursor-pointer py-2 px-4 rounded-md'`,
|
|
28
|
+
'[class.text-neutral-900]': 'isBase()',
|
|
29
|
+
'[class.text-neutral-100]': 'isPrimary()',
|
|
30
|
+
'[class.bg-neutral-100]': 'isBase()',
|
|
31
|
+
'[class.hover:bg-neutral-200]': 'isBase()',
|
|
32
|
+
'[class.active:bg-neutral-300]': 'isBase()',
|
|
33
|
+
'[class.bg-blue-400]': 'isPrimary()',
|
|
34
|
+
'[class.hover:bg-blue-500]': 'isPrimary()',
|
|
35
|
+
'[class.active:bg-blue-600]': 'isPrimary()',
|
|
36
|
+
},
|
|
14
37
|
imports: [],
|
|
15
38
|
}]
|
|
16
|
-
}] });
|
|
39
|
+
}], propDecorators: { color: [{ type: i0.Input, args: [{ isSignal: true, alias: "dma-button", required: false }] }] } });
|
|
17
40
|
|
|
18
41
|
/**
|
|
19
42
|
* Public API Surface of @dnd-mapp/shared-ui
|
|
@@ -23,5 +46,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImpor
|
|
|
23
46
|
* Generated bundle index. Do not edit.
|
|
24
47
|
*/
|
|
25
48
|
|
|
26
|
-
export {
|
|
49
|
+
export { ButtonColors, ButtonComponent, DEFAULT_BUTTON_COLOR, buttonColorAttribute };
|
|
27
50
|
//# sourceMappingURL=dnd-mapp-shared-ui.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dnd-mapp-shared-ui.mjs","sources":["../../../projects/shared-ui/src/lib/shared-ui.ts","../../../projects/shared-ui/src/public-api.ts","../../../projects/shared-ui/src/dnd-mapp-shared-ui.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"dnd-mapp-shared-ui.mjs","sources":["../../../projects/shared-ui/src/lib/button/button-color.ts","../../../projects/shared-ui/src/lib/button/button.component.ts","../../../projects/shared-ui/src/public-api.ts","../../../projects/shared-ui/src/dnd-mapp-shared-ui.ts"],"sourcesContent":["import { AttributeInput } from '../attribute-input';\n\nexport const ButtonColors = {\n PRIMARY: 'primary',\n BASE: 'base',\n} as const;\n\nexport type ButtonColor = (typeof ButtonColors)[keyof typeof ButtonColors];\n\nexport const DEFAULT_BUTTON_COLOR: ButtonColor = ButtonColors.BASE;\n\nexport function buttonColorAttribute(value: AttributeInput<ButtonColor>) {\n return Object.values(ButtonColors).find((color) => value === color) ?? DEFAULT_BUTTON_COLOR;\n}\n","import { Component, computed, input } from '@angular/core';\nimport { buttonColorAttribute, ButtonColors, DEFAULT_BUTTON_COLOR } from './button-color';\n\n@Component({\n // eslint-disable-next-line @angular-eslint/component-selector\n selector: 'button[dma-button]',\n template: `<ng-content />`,\n host: {\n '[class]': `'font-semibold cursor-pointer py-2 px-4 rounded-md'`,\n '[class.text-neutral-900]': 'isBase()',\n '[class.text-neutral-100]': 'isPrimary()',\n '[class.bg-neutral-100]': 'isBase()',\n '[class.hover:bg-neutral-200]': 'isBase()',\n '[class.active:bg-neutral-300]': 'isBase()',\n '[class.bg-blue-400]': 'isPrimary()',\n '[class.hover:bg-blue-500]': 'isPrimary()',\n '[class.active:bg-blue-600]': 'isPrimary()',\n },\n imports: [],\n})\nexport class ButtonComponent {\n public readonly color = input(DEFAULT_BUTTON_COLOR, { transform: buttonColorAttribute, alias: 'dma-button' });\n\n protected readonly isBase = computed(() => this.color() === ButtonColors.BASE);\n\n protected readonly isPrimary = computed(() => this.color() === ButtonColors.PRIMARY);\n}\n","/**\n * Public API Surface of @dnd-mapp/shared-ui\n */\nexport * from './lib';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG;AACxB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,IAAI,EAAE,MAAM;;AAKT,MAAM,oBAAoB,GAAgB,YAAY,CAAC;AAExD,SAAU,oBAAoB,CAAC,KAAkC,EAAA;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,CAAC,IAAI,oBAAoB;A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AAO,EAAE,EAAE;AACd,iBAAA;;;ACnBD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
[← Back to Library Overview](../../../README.md#-ui-components)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Button Component (`dma-button`)
|
|
6
|
+
|
|
7
|
+
The `ButtonComponent` is a versatile, high-performance UI element built with **Angular 21 signals** and **Tailwind CSS v4**. It is designed as an attribute selector for standard HTML `<button>` elements, ensuring native accessibility and browser behavior while applying the **D&D Mapp** design system.
|
|
8
|
+
|
|
9
|
+
## 🏰 Overview
|
|
10
|
+
|
|
11
|
+
- **Type**: Standalone Component.
|
|
12
|
+
- **Selector**: `button[dma-button]`
|
|
13
|
+
- **Styling**: Tailwind CSS v4 (via Host Bindings).
|
|
14
|
+
- **Logic**: 100% Signal-based (Inputs & Computed state).
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🚀 Usage
|
|
19
|
+
|
|
20
|
+
### 1. Import
|
|
21
|
+
|
|
22
|
+
Add `ButtonComponent` to your standalone component's `imports` array:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Component } from '@angular/core';
|
|
26
|
+
import { ButtonComponent } from '@dnd-mapp/shared-ui';
|
|
27
|
+
|
|
28
|
+
@Component({
|
|
29
|
+
selector: 'app-encounter-action',
|
|
30
|
+
template: `
|
|
31
|
+
<!-- Defaults to 'base' -->
|
|
32
|
+
<button dma-button>Base Action</button>
|
|
33
|
+
|
|
34
|
+
<!-- Explicit 'primary' -->
|
|
35
|
+
<button dma-button="primary">Roll Initiative</button>
|
|
36
|
+
`,
|
|
37
|
+
imports: [ButtonComponent]
|
|
38
|
+
})
|
|
39
|
+
export class EncounterActionComponent {}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Styles Requirement
|
|
43
|
+
|
|
44
|
+
Ensure Tailwind CSS v4 is configured in your project to process the utility classes defined in the component host metadata.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🎨 API Reference
|
|
49
|
+
|
|
50
|
+
### Inputs
|
|
51
|
+
|
|
52
|
+
| Input | Attribute | Type | Default | Description |
|
|
53
|
+
|---------|--------------|----------------|----------|--------------------------------------------|
|
|
54
|
+
| `color` | `dma-button` | `ButtonColors` | `'base'` | Determines the visual style of the button. |
|
|
55
|
+
|
|
56
|
+
### Color Variants
|
|
57
|
+
|
|
58
|
+
The component leverages `computed` signals to toggle Tailwind classes dynamically:
|
|
59
|
+
|
|
60
|
+
1. **Base (`base`)**
|
|
61
|
+
- **Trigger**: `<button dma-button>` or `<button dma-button="base">`
|
|
62
|
+
- **Styles**: Light neutral background (`bg-neutral-100`), dark text (`text-neutral-900`).
|
|
63
|
+
- **States**: Subtle darkening on hover/active.
|
|
64
|
+
|
|
65
|
+
2. **Primary (`primary`)**
|
|
66
|
+
- **Trigger**: `<button dma-button="primary">`
|
|
67
|
+
- **Styles**: Blue background (`bg-blue-400`), light text (`text-neutral-100`).
|
|
68
|
+
- **States**: Vibrant blue scaling (`hover:bg-blue-500`, `active:bg-blue-600`).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🛠 Technical Details
|
|
73
|
+
|
|
74
|
+
### Signal Implementation
|
|
75
|
+
|
|
76
|
+
The component uses modern Angular Signals for reactive state management:
|
|
77
|
+
|
|
78
|
+
- **`input()`**: Uses a `transform` function (`buttonColorAttribute`) to sanitize input values and an `alias` to support the shorthand attribute syntax.
|
|
79
|
+
- **`computed()`**: Derive boolean states (`isBase`, `isPrimary`) for highly efficient change detection.
|
|
80
|
+
|
|
81
|
+
### Tailwind Integration
|
|
82
|
+
|
|
83
|
+
Styles are applied directly to the host element using high-performance class bindings:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
host: {
|
|
87
|
+
'[class]': `'font-semibold cursor-pointer py-2 px-4 rounded-md'`,
|
|
88
|
+
'[class.bg-blue-400]': 'isPrimary()',
|
|
89
|
+
// ... other conditional classes
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Attribute Shorthand & Transformation
|
|
94
|
+
|
|
95
|
+
The `dma-button` alias allows the attribute itself to serve as the input. If an empty string or invalid value is provided, the `buttonColorAttribute` transformer ensures it safely falls back to `DEFAULT_BUTTON_COLOR`.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 🧪 Examples
|
|
100
|
+
|
|
101
|
+
### Primary Action (Natural 20 Style)
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<button dma-button="primary" (click)="rollDice()">Attack!</button>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Secondary / Cancel Action
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<button dma-button (click)="closeModal()">Dismiss</button>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 📜 License
|
|
116
|
+
|
|
117
|
+
This component is part of the `@dnd-mapp/shared-ui` proprietary library. Refer to the root [LICENSE](https://github.com/dnd-mapp/shared-ui/blob/main/LICENSE) for usage restrictions.
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import * as _dnd_mapp_shared_ui from '@dnd-mapp/shared-ui';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type AttributeInput<T> = T | '';
|
|
5
|
+
|
|
6
|
+
declare const ButtonColors: {
|
|
7
|
+
readonly PRIMARY: "primary";
|
|
8
|
+
readonly BASE: "base";
|
|
9
|
+
};
|
|
10
|
+
type ButtonColor = (typeof ButtonColors)[keyof typeof ButtonColors];
|
|
11
|
+
declare const DEFAULT_BUTTON_COLOR: ButtonColor;
|
|
12
|
+
declare function buttonColorAttribute(value: AttributeInput<ButtonColor>): ButtonColor;
|
|
13
|
+
|
|
14
|
+
declare class ButtonComponent {
|
|
15
|
+
readonly color: _angular_core.InputSignalWithTransform<_dnd_mapp_shared_ui.ButtonColor, AttributeInput<_dnd_mapp_shared_ui.ButtonColor>>;
|
|
16
|
+
protected readonly isBase: _angular_core.Signal<boolean>;
|
|
17
|
+
protected readonly isPrimary: _angular_core.Signal<boolean>;
|
|
18
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ButtonComponent, never>;
|
|
19
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<ButtonComponent, "button[dma-button]", never, { "color": { "alias": "dma-button"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
|
|
6
20
|
}
|
|
7
21
|
|
|
8
|
-
export {
|
|
22
|
+
export { ButtonColors, ButtonComponent, DEFAULT_BUTTON_COLOR, buttonColorAttribute };
|
|
23
|
+
export type { ButtonColor };
|