feat: Add the design for the new Input component (#10258)
Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
<script setup>
|
||||||
|
import Input from './Input.vue';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Story title="Components/Input" :layout="{ type: 'grid', width: '400' }">
|
||||||
|
<Variant title="Default">
|
||||||
|
<div class="p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input placeholder="Default Input" />
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="With Label">
|
||||||
|
<div class="p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input label="Username" placeholder="Enter your username" />
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="Disabled">
|
||||||
|
<div class="p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input label="Disabled Input" placeholder="Can't type here" disabled />
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="With Message">
|
||||||
|
<div class="flex flex-col gap-4 p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input
|
||||||
|
label="Email"
|
||||||
|
placeholder="Enter your email"
|
||||||
|
message="We'll never share your email."
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
label="Password"
|
||||||
|
type="password"
|
||||||
|
placeholder="Enter your password"
|
||||||
|
message="Password is incorrect"
|
||||||
|
message-type="error"
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
label="Verification Code"
|
||||||
|
placeholder="Enter the code"
|
||||||
|
message="Code verified successfully"
|
||||||
|
message-type="success"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="Different Types">
|
||||||
|
<div class="flex flex-col gap-4 p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input label="Text" type="text" placeholder="Text input" />
|
||||||
|
<Input label="Number" type="number" placeholder="Number input" />
|
||||||
|
<Input label="Password" type="password" placeholder="Password input" />
|
||||||
|
<Input label="Email" type="email" placeholder="Email input" />
|
||||||
|
<Input label="Date" type="date" />
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
|
||||||
|
<Variant title="Custom Input Class">
|
||||||
|
<div class="p-4 bg-white dark:bg-slate-800">
|
||||||
|
<Input
|
||||||
|
label="Custom Style"
|
||||||
|
placeholder="Custom input class"
|
||||||
|
custom-input-class="border-yellow-500 dark:border-yellow-700"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Variant>
|
||||||
|
</Story>
|
||||||
|
</template>
|
||||||
92
app/javascript/dashboard/components-next/input/Input.vue
Normal file
92
app/javascript/dashboard/components-next/input/Input.vue
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'text',
|
||||||
|
},
|
||||||
|
customInputClass: {
|
||||||
|
type: [String, Object, Array],
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
messageType: {
|
||||||
|
type: String,
|
||||||
|
default: 'info',
|
||||||
|
validator: value => ['info', 'error', 'success'].includes(value),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
defineEmits(['update:modelValue']);
|
||||||
|
const messageClass = computed(() => {
|
||||||
|
switch (props.messageType) {
|
||||||
|
case 'error':
|
||||||
|
return 'text-red-500 dark:text-red-400';
|
||||||
|
case 'success':
|
||||||
|
return 'text-green-500 dark:text-green-400';
|
||||||
|
default:
|
||||||
|
return 'text-slate-500 dark:text-slate-400';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const inputBorderClass = computed(() => {
|
||||||
|
switch (props.messageType) {
|
||||||
|
case 'error':
|
||||||
|
return 'border-red-500 dark:border-red-400';
|
||||||
|
default:
|
||||||
|
return 'border-slate-100 dark:border-slate-700/50';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="relative flex flex-col gap-1">
|
||||||
|
<label
|
||||||
|
v-if="label"
|
||||||
|
:for="id"
|
||||||
|
class="mb-0.5 text-sm font-medium text-gray-900 dark:text-gray-50"
|
||||||
|
>
|
||||||
|
{{ label }}
|
||||||
|
</label>
|
||||||
|
<!-- Added prefix slot to allow adding icons to the input -->
|
||||||
|
<slot name="prefix" />
|
||||||
|
<input
|
||||||
|
:id="id"
|
||||||
|
:value="modelValue"
|
||||||
|
:class="[customInputClass, inputBorderClass]"
|
||||||
|
:type="type"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="flex w-full reset-base text-sm h-8 pl-3 pr-2 rtl:pr-3 rtl:pl-2 py-1.5 !mb-0 border rounded-lg focus:border-woot-500 dark:focus:border-woot-600 bg-white dark:bg-slate-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-200 dark:placeholder:text-slate-500 disabled:cursor-not-allowed disabled:opacity-50 text-slate-900 dark:text-white transition-all duration-500 ease-in-out"
|
||||||
|
@input="$emit('update:modelValue', $event.target.value)"
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
v-if="message"
|
||||||
|
class="mt-1 mb-0 text-xs transition-all duration-500 ease-in-out"
|
||||||
|
:class="messageClass"
|
||||||
|
>
|
||||||
|
{{ message }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user