Add new UI components: Card and Checkbox; enhance Input and Button with additional props

This commit is contained in:
lucast committed 2025-12-05 02:34:58 +01:00
1 parent 89f84e571f
commit e1716c3e61
6 files changed
+205 -15

No files matched your search

+1
View File
@@ -5,5 +5,6 @@ $color-placeholder-text: rgba(255, 255, 255, 0.44);
$color-border: rgba(255, 255, 255, 0.16); $color-border: rgba(255, 255, 255, 0.16);
$color-button: rgba(255, 255, 255, 0.08); $color-button: rgba(255, 255, 255, 0.08);
$color-button-hover: rgba(255, 255, 255, 0.16); $color-button-hover: rgba(255, 255, 255, 0.16);
$color-attention: #fc8181;
$standard-border-radius: 0.3rem; $standard-border-radius: 0.3rem;
+1
View File
@@ -3,4 +3,5 @@
html { html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
color: white;
} }
+10 -1
View File
@@ -7,6 +7,7 @@ interface ButtonProps {
variant?: "default" | "ghost" variant?: "default" | "ghost"
full?: boolean full?: boolean
iconName?: string iconName?: string
centerText?: boolean
} }
const props = withDefaults(defineProps<ButtonProps>(), { const props = withDefaults(defineProps<ButtonProps>(), {
@@ -23,7 +24,11 @@ const props = withDefaults(defineProps<ButtonProps>(), {
:to="props.to" :to="props.to"
:class="[ :class="[
`button type-${props.variant}`, `button type-${props.variant}`,
{ full: props.full, icon: $slots.icon || props.iconName }, {
full: props.full,
icon: $slots.icon || props.iconName,
center: props.centerText,
},
]" ]"
> >
<span class="icon-wrapper"> <span class="icon-wrapper">
@@ -48,6 +53,10 @@ const props = withDefaults(defineProps<ButtonProps>(), {
.full { .full {
width: 100%; width: 100%;
text-align: left; text-align: left;
&.center {
justify-content: center;
}
} }
.button, .button,
+23
View File
@@ -0,0 +1,23 @@
<script setup lang="ts">
interface CardProps {
width?: string
}
const props = defineProps<CardProps>()
</script>
<template>
<article class="card" :style="{ width: props.width }">
<slot />
</article>
</template>
<style lang="scss" scoped>
@use "@/styles/variables" as *;
.card {
border: 1px solid $color-border;
border-radius: $standard-border-radius;
padding: 1rem;
}
</style>
+116
View File
@@ -0,0 +1,116 @@
<script setup lang="ts">
interface CheckboxProps {
label?: string
name?: string
required?: boolean
full?: boolean
}
const model = defineModel<boolean>({ default: false })
const emit = defineEmits<{
(e: "change", value: boolean): void
}>()
const props = defineProps<CheckboxProps>()
</script>
<template>
<div class="checkbox-wrapper" :class="{ full: props.full }">
<label :for="props.name" class="checkbox-label">
<input
type="checkbox"
:id="props.name"
:name="props.name"
v-model="model"
@change="emit('change', model)"
:required="props.required"
/>
<span class="checkmark"></span>
<slot v-if="$slots.label" name="label" />
<span v-else-if="props.label">{{ props.label }}</span>
<span v-if="props.required" class="required">*</span>
</label>
</div>
</template>
<style lang="scss" scoped>
@use "@/styles/variables" as *;
@use "@/styles/util" as *;
.checkbox-wrapper {
display: inline-block;
position: relative;
user-select: none;
&.full {
display: block;
width: 100%;
}
}
.checkbox-label {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
position: relative;
padding-left: 1.6rem;
@include fontSize(16px);
}
.checkbox-label input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 1rem;
width: 1rem;
border: 1px solid $color-border;
border-radius: $standard-border-radius;
background-color: transparent;
transition: background-color 0.2s, border-color 0.2s;
}
.checkbox-label input:checked ~ .checkmark {
background-color: $color-accent;
border-color: $color-accent;
}
.checkbox-label input:focus-visible ~ .checkmark {
outline: 2px solid $color-accent;
outline-offset: 2px;
}
.checkmark::after {
content: "";
position: absolute;
display: none;
left: 0.28rem;
top: 0.05rem;
width: 0.3rem;
height: 0.6rem;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.checkbox-label input:checked ~ .checkmark::after {
display: block;
}
.required {
color: $color-attention;
margin-left: 0.3em;
}
</style>
+54 -14
View File
@@ -1,8 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
type InputType = HTMLInputElement["type"]
type AutocompleteType = HTMLInputElement["autocomplete"]
interface InputProps { interface InputProps {
placeholder?: string placeholder?: string
full?: boolean full?: boolean
iconName?: string iconName?: string
type?: InputType
name?: string
required?: boolean
autocomplete?: AutocompleteType
} }
const value = defineModel("value") const value = defineModel("value")
@@ -16,25 +23,51 @@ const props = defineProps<InputProps>()
</script> </script>
<template> <template>
<div <div class="input-wrapper">
class="input" <label v-if="$slots.label" :for="props.name">
:class="{ full: props.full, icon: $slots.icon || props.iconName }" <slot name="label" />
> <span v-if="props.required" class="required">*</span>
<span class="icon-wrapper"> </label>
<slot name="icon" v-if="!props.iconName" /> <div
<Icon :name="props.iconName" v-else /> class="input"
</span> :class="{ full: props.full, icon: $slots.icon || props.iconName }"
<input >
:placeholder="props.placeholder" <span class="icon-wrapper">
v-model="value" <slot name="icon" v-if="!props.iconName" />
@input="(e) => emit('input', e.target?.value)" <Icon :name="props.iconName" v-else />
@focus="emit('focus')" </span>
/>
<input
:placeholder="props.placeholder"
v-model="value"
@input="(e) => emit('input', e.target?.value)"
@focus="emit('focus')"
:type="props.type"
:name="props.name"
:id="props.name"
:required="props.required"
:autocomplete="props.autocomplete"
/>
</div>
</div> </div>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@use "@/styles/variables" as *; @use "@/styles/variables" as *;
@use "@/styles/util" as *;
.input-wrapper {
& > label {
display: block;
@include fontSize(14px);
margin-bottom: 0.4rem;
.required {
margin-left: 0.3em;
color: $color-attention;
}
}
}
.input { .input {
border-radius: $standard-border-radius; border-radius: $standard-border-radius;
@@ -52,6 +85,13 @@ const props = defineProps<InputProps>()
& input { & input {
width: 100%; width: 100%;
background: none; background: none;
&:-webkit-autofill,
&:-webkit-autofill:hover,
&:-webkit-autofill:focus {
box-shadow: 0 0 0px 1000px $color-background inset !important;
-webkit-text-fill-color: $color-text !important;
}
} }
& input:focus { & input:focus {