-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FormKit): work on Button component
- Loading branch information
1 parent
7d78c39
commit fec6bf9
Showing
7 changed files
with
154 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/docs/page-config/extensions/formkit/examples/Button.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script setup lang="ts"> | ||
import * as types from '@vuestic/formkit' | ||
type HTMLElementEvent<T = HTMLElement> = Event & { | ||
target: T; | ||
} | ||
const randomColor = (e: HTMLElementEvent) => { | ||
const hex = Math | ||
.floor(Math.random()*16777215) | ||
.toString(16); | ||
e.target!.setAttribute( | ||
'style', | ||
'background-color: #' + hex + '88;' | ||
) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="grid gap-6"> | ||
<FormKit | ||
:type="types.button" | ||
color="danger" | ||
label="Checkout my label" | ||
help="You can use the label prop." | ||
/> | ||
|
||
<FormKit | ||
:type="types.button" | ||
help="You can use the default slot." | ||
prefix-icon="check" | ||
> | ||
I have slot content | ||
</FormKit> | ||
|
||
<FormKit | ||
:type="types.button" | ||
help="You can bind event listeners." | ||
@click="randomColor" | ||
> | ||
Click me! | ||
</FormKit> | ||
</div> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,46 @@ | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
<script setup lang="ts"> | ||
import * as types from '../../src' | ||
export default defineComponent({ | ||
setup() { | ||
return { | ||
types | ||
} | ||
} | ||
}) | ||
type HTMLElementEvent<T = HTMLElement> = Event & { | ||
target: T; | ||
} | ||
const randomColor = (e: HTMLElementEvent) => { | ||
const hex = Math | ||
.floor(Math.random()*16777215) | ||
.toString(16); | ||
e.target!.setAttribute( | ||
'style', | ||
'background-color: #' + hex + '88;' | ||
) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="pa-4"> | ||
<table class="va-table"> | ||
<tbody> | ||
<tr | ||
v-for="(type, typeName) in types" | ||
:key="typeName" | ||
> | ||
<td>{{ typeName }}</td> | ||
<td> | ||
<FormKit | ||
v-if="type" | ||
:type="type" | ||
:label="typeName" | ||
validation="required|min:3" | ||
name="test" | ||
help="help" | ||
/> | ||
<p v-else> | ||
null | ||
</p> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<div class="d-flex flex-direction-column pa-4" style="gap: 1.5rem"> | ||
<FormKit | ||
:type="types.text" | ||
label="Test" | ||
validation="required|min:3" | ||
name="test" | ||
help="aaa" | ||
:type="types.button" | ||
color="danger" | ||
label="Checkout my label" | ||
help="You can use the label prop." | ||
/> | ||
|
||
<FormKit | ||
:type="types.button" | ||
help="You can use the default slot." | ||
prefix-icon="check" | ||
> | ||
I have slot content | ||
</FormKit> | ||
|
||
<FormKit | ||
:type="types.button" | ||
help="You can bind event listeners." | ||
@click="randomColor" | ||
> | ||
Click me! | ||
</FormKit> | ||
</div> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createSection, type FormKitSchemaExtendableSection } from "@formkit/inputs"; | ||
|
||
/** | ||
* Icon section used by all icons | ||
* | ||
* @public | ||
*/ | ||
export const icon = ( | ||
sectionKey: string, | ||
): FormKitSchemaExtendableSection => { | ||
return createSection(`${sectionKey}Icon`, () => { | ||
return { | ||
if: `$${sectionKey}Icon`, | ||
$cmp: 'VaIcon', | ||
props: { | ||
class: 'material-icons', | ||
onClick: `$handlers.iconClick(${sectionKey})`, | ||
role: `$fns.iconRole(${sectionKey})`, | ||
tabindex: `$fns.iconRole(${sectionKey}) === "button" && "0" || undefined`, | ||
}, | ||
children: '$prefixIcon' | ||
} | ||
})() | ||
} |