grav-svelte 0.0.2 → 0.0.4
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 +16 -4
- package/dist/Button/Button.svelte +13 -3
- package/dist/Button/Button.svelte.d.ts +1 -3
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@ npm install grav-svelte
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
You can import components in two ways:
|
|
14
|
+
|
|
15
|
+
### Method 1: Import from the package root
|
|
13
16
|
```svelte
|
|
14
17
|
<script>
|
|
15
18
|
import { Button } from 'grav-svelte';
|
|
@@ -18,17 +21,26 @@ npm install grav-svelte
|
|
|
18
21
|
<Button variant="primary" size="medium">Click me</Button>
|
|
19
22
|
```
|
|
20
23
|
|
|
24
|
+
### Method 2: Import the component directly
|
|
25
|
+
```svelte
|
|
26
|
+
<script>
|
|
27
|
+
import Button from 'grav-svelte/Button';
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<Button variant="primary" size="medium">Click me</Button>
|
|
31
|
+
```
|
|
32
|
+
|
|
21
33
|
## Components
|
|
22
34
|
|
|
23
35
|
### Button
|
|
24
36
|
|
|
25
|
-
A versatile button component with multiple variants and sizes.
|
|
37
|
+
A versatile button component with multiple variants and sizes. The button toggles between primary (blue) and danger (red) variants when clicked.
|
|
26
38
|
|
|
27
39
|
#### Props
|
|
28
40
|
|
|
29
41
|
| Prop | Type | Default | Description |
|
|
30
42
|
|------|------|---------|-------------|
|
|
31
|
-
| variant | 'primary' \| 'secondary' \| 'outline' | 'primary' | The visual style of the button |
|
|
43
|
+
| variant | 'primary' \| 'secondary' \| 'outline' \| 'danger' | 'primary' | The visual style of the button |
|
|
32
44
|
| size | 'small' \| 'medium' \| 'large' | 'medium' | The size of the button |
|
|
33
45
|
| disabled | boolean | false | Whether the button is disabled |
|
|
34
46
|
| type | 'button' \| 'submit' \| 'reset' | 'button' | The HTML button type |
|
|
@@ -37,7 +49,7 @@ A versatile button component with multiple variants and sizes.
|
|
|
37
49
|
#### Examples
|
|
38
50
|
|
|
39
51
|
```svelte
|
|
40
|
-
<!-- Primary button -->
|
|
52
|
+
<!-- Primary button (toggles to danger on click) -->
|
|
41
53
|
<Button variant="primary">Primary Button</Button>
|
|
42
54
|
|
|
43
55
|
<!-- Secondary button -->
|
|
@@ -54,7 +66,7 @@ A versatile button component with multiple variants and sizes.
|
|
|
54
66
|
<!-- Disabled state -->
|
|
55
67
|
<Button disabled>Disabled Button</Button>
|
|
56
68
|
|
|
57
|
-
<!-- With click handler -->
|
|
69
|
+
<!-- With custom click handler -->
|
|
58
70
|
<Button on:click={() => alert('Clicked!')}>Click me</Button>
|
|
59
71
|
```
|
|
60
72
|
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
export let variant: 'primary' | 'secondary' | 'outline' = 'primary';
|
|
2
|
+
export let variant: 'primary' | 'secondary' | 'outline' | 'danger' = 'primary';
|
|
3
3
|
export let size: 'small' | 'medium' | 'large' = 'medium';
|
|
4
4
|
export let disabled = false;
|
|
5
5
|
export let type: 'button' | 'submit' | 'reset' = 'button';
|
|
6
6
|
export let class_name = '';
|
|
7
7
|
|
|
8
|
+
let isDanger = false;
|
|
9
|
+
|
|
8
10
|
const baseClasses = 'rounded font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2';
|
|
9
11
|
|
|
10
12
|
const variantClasses = {
|
|
11
13
|
primary: 'bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500',
|
|
12
14
|
secondary: 'bg-gray-600 text-white hover:bg-gray-700 focus:ring-gray-500',
|
|
13
|
-
outline: 'border-2 border-blue-600 text-blue-600 hover:bg-blue-50 focus:ring-blue-500'
|
|
15
|
+
outline: 'border-2 border-blue-600 text-blue-600 hover:bg-blue-50 focus:ring-blue-500',
|
|
16
|
+
danger: 'bg-red-600 text-white hover:bg-red-700 focus:ring-red-500'
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
const sizeClasses = {
|
|
@@ -21,6 +24,13 @@
|
|
|
21
24
|
|
|
22
25
|
const disabledClasses = 'opacity-50 cursor-not-allowed';
|
|
23
26
|
|
|
27
|
+
function handleClick(event: MouseEvent) {
|
|
28
|
+
if (!disabled) {
|
|
29
|
+
isDanger = !isDanger;
|
|
30
|
+
variant = isDanger ? 'danger' : 'primary';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
$: classes = `${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]} ${disabled ? disabledClasses : ''} ${class_name}`;
|
|
25
35
|
</script>
|
|
26
36
|
|
|
@@ -28,7 +38,7 @@
|
|
|
28
38
|
{type}
|
|
29
39
|
{disabled}
|
|
30
40
|
class={classes}
|
|
31
|
-
on:click
|
|
41
|
+
on:click={handleClick}
|
|
32
42
|
{...$$restProps}
|
|
33
43
|
>
|
|
34
44
|
<slot />
|
|
@@ -2,15 +2,13 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
variant?: "primary" | "secondary" | "outline" | undefined;
|
|
5
|
+
variant?: "primary" | "secondary" | "outline" | "danger" | undefined;
|
|
6
6
|
size?: "small" | "medium" | "large" | undefined;
|
|
7
7
|
disabled?: boolean | undefined;
|
|
8
8
|
type?: "button" | "submit" | "reset" | undefined;
|
|
9
9
|
class_name?: string | undefined;
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
|
-
click: MouseEvent;
|
|
13
|
-
} & {
|
|
14
12
|
[evt: string]: CustomEvent<any>;
|
|
15
13
|
};
|
|
16
14
|
slots: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grav-svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A collection of Svelte components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"svelte": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./Button": {
|
|
32
|
+
"types": "./dist/Button/index.d.ts",
|
|
33
|
+
"svelte": "./dist/Button/Button.svelte"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"peerDependencies": {
|