Skip to content

Commit

Permalink
Merge pull request #32 from LucasWerey/feat/11
Browse files Browse the repository at this point in the history
feat(dslib): add SelectField
  • Loading branch information
LucasWerey authored Jan 16, 2024
2 parents 595a066 + 40e5b8f commit 2eaa603
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You will find the last version of the library here : https://github.com/LucasWer
In your main project import the library :

```bash
yarn add @lucaswerey/[email protected].52
yarn add @lucaswerey/[email protected].55
```

## Use docker
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lucaswerey/dslib-pfe",
"version": "0.0.55",
"version": "0.0.56",
"private": false,
"main": "./lib/index.umd.js",
"module": "./lib/index.mjs",
Expand Down
16 changes: 15 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<script setup lang="ts">
import './assets/index.css'
const handleUpdate = (value: string) => {
console.log(value)
}
</script>

<template>
<ChipContainer label="Espagnol" hasIcon />
<SelectField
title="Date"
:options="[
{ value: 'Mois', label: 'Mois' },
{ value: 'Années', label: 'Années' },
{ value: 'Semaines', label: 'Semaines' },
{ value: 'Jours', label: 'Jours' }
]"
:default="'go'"
@update:modelValue="handleUpdate"
/>
</template>
Binary file added src/assets/fonts/Eina01-Bold.ttf
Binary file not shown.
Binary file added src/assets/fonts/Eina01-Regular.ttf
Binary file not shown.
20 changes: 20 additions & 0 deletions src/assets/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@500;700;800&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

@font-face {
font-family: 'Eina1';
src: url('./fonts/Eina01-Regular.ttf') format('truetype');
font-weight: 500;
font-style: normal;
}

@font-face {
font-family: 'Eina1';
src: url('./fonts/Eina01-Bold.ttf') format('truetype');
font-weight: 700;
font-style: normal;
}

* {
font-family: 'Inter', sans-serif;
}
2 changes: 2 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ declare module 'vue' {
'InputField.story': typeof import('./components/CTA/InputField/InputField.story.vue')['default']
Loader: typeof import('./components/Indicators/Loader/Loader.vue')['default']
'Loader.story': typeof import('./components/Indicators/Loader/Loader.story.vue')['default']
SelectField: typeof import('./components/CTA/SelectField/SelectField.vue')['default']
'SelectField.story': typeof import('./components/CTA/SelectField/SelectField.story.vue')['default']
SnackBar: typeof import('./components/Indicators/SnackBar/SnackBar.vue')['default']
'SnackBar.story': typeof import('./components/Indicators/SnackBar/SnackBar.story.vue')['default']
StepIndicator: typeof import('./components/Indicators/StepIndicator/StepIndicator.vue')['default']
Expand Down
37 changes: 37 additions & 0 deletions src/components/CTA/SelectField/SelectField.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Avaible colors:
basic:
black: '#1B1B1E',
darkgrey: '#787878',
grey: '#CDCDCD',
lightgrey: '#ECECEC',
verylightgrey: '#F6F6F6',
white: '#FAFAFA'
primary:
DEFAULT: '#000000',
light: '#00F2A5',
charcoal: '#373F51',
moonstone: '#58A4B0',
powder: '#A9BCD0',
platinum: '#D8DBE2'
transparent: 'transparent',
current: 'currentColor',
inherit: 'inherit',
error: '#FF5656',
warning: '#FFC85C',
success: '#7BC079',
info: '#333333'
*/

export interface SelectFieldOption {
value: string
label: string
}

export interface SelectFieldProps {
options: SelectFieldOption[]
default: string
tabindex: number
title: string
}
38 changes: 38 additions & 0 deletions src/components/CTA/SelectField/SelectField.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mount } from '@vue/test-utils'
import { it, describe, expect } from 'vitest'

import SelectField from './SelectField.vue'
import { nextTick } from 'vue'

describe('SelectField.vue', () => {
it('renders title prop', async () => {
const wrapper = mount(SelectField, {
props: {
title: 'Test Title',
options: [{ label: 'Option 1', value: 'option1' }],
default: 'option1'
}
})

await nextTick()

expect(wrapper.find('h1').text()).toBe('Test Title')
})

it('emits update:modelValue event when an option is clicked', async () => {
const wrapper = mount(SelectField, {
props: {
title: 'Test Title',
options: [{ label: 'Option 1', value: 'option1' }],
default: 'option1'
}
})

await nextTick()

await wrapper.find('.items div').trigger('click')

expect(wrapper.emitted()).toHaveProperty('update:modelValue')
expect(wrapper.emitted()['update:modelValue'][0]).toEqual(['option1'])
})
})
47 changes: 47 additions & 0 deletions src/components/CTA/SelectField/SelectField.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<Story title="Select Field" group="cta">
<template #controls>
<ControlDescription>
<HstSelect v-model="controls.default" :options="options" title="Options" />
</ControlDescription>
<ControlDescription>
<HstText v-model="controls.title" :options="title" title="Title" />
</ControlDescription>
</template>
<Variant title="Playground" :auto-props-disabled="true">
<div class="h-[30vh]">
<SelectField
:options="options"
:default="controls.default"
:title="controls.title"
@update:modelValue="logEvent('update', $event)"
/>
</div>
</Variant>
</Story>
</template>

<script setup lang="ts">
import { SelectFieldOption } from './SelectField.model'

Check failure on line 25 in src/components/CTA/SelectField/SelectField.story.vue

View workflow job for this annotation

GitHub Actions / build

'SelectFieldOption' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
import { logEvent } from 'histoire/client'
interface Controls {
options: SelectFieldOption[]
default: string
title: string
}
const controls = reactive<Controls>({
options: [
{ value: 'Mois', label: 'Mois' },
{ value: 'Années', label: 'Années' },
{ value: 'Semaines', label: 'Semaines' },
{ value: 'Jours', label: 'Jours' }
],
default: 'Mois',
title: 'Date'
})
const options = computed(() => controls.options)
const title = computed(() => controls.title)
</script>
77 changes: 77 additions & 0 deletions src/components/CTA/SelectField/SelectField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<div class="flex h-[72px] w-[200px] flex-col gap-2">
<h1 class="font-eina1 text-2 font-bold uppercase text-basic-black">
{{ title }}
</h1>
<div class="relative h-full w-full text-left outline-none">
<div
class="full flex h-[48px] w-full cursor-pointer select-none items-center justify-between rounded-[4px] border border-basic-grey bg-basic-white px-[16px] py-[13px] font-eina1 text-4 lowercase text-basic-darkgrey"
:class="{ 'h-[48px] rounded-b-[0px] ': open }"
@click="open = !open"
@blur="open = false"
>
{{ selected }}
<IconsBase
:rotate="open ? 180 : 0"
name="chevronDown"
class="h-[24px] w-[24px] bg-basic-white"
color="darkgrey"
/>
</div>
<div class="items" v-show="open">
<div
v-for="(option, i) of options"
:key="i"
@click="handleClick(option)"
:class="[
'flex h-[48px] w-full cursor-pointer border-b border-l border-r border-basic-grey px-[16px] py-[13px] font-eina1 text-4 lowercase text-basic-darkgrey hover:border-basic-lightgrey hover:bg-basic-lightgrey',
{ 'rounded-b-[4px]': i === (options?.length ?? 0) - 1 },
{
' border-basic-lightgrey bg-basic-lightgrey font-bold text-basic-darkgrey':
option.value === selectedValue
},
{
' bg-basic-white': option.value != selectedValue
}
]"
>
{{ option.label }}
</div>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import { SelectFieldOption } from './SelectField.model'

Check failure on line 46 in src/components/CTA/SelectField/SelectField.vue

View workflow job for this annotation

GitHub Actions / build

'SelectFieldOption' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
const props = defineProps({
options: {
type: Array as PropType<SelectFieldOption[]>,
required: true
},
default: { String, required: true },
title: { String, required: true }
})
const selectedValue: Ref<string> = ref('')
const selected = computed(() => {
if (selectedValue.value) return selectedValue.value
if (props.default) return props.default
if (props.options.length > 0) return props.options[0].value
return null
})
const open = ref(false)
onMounted(() => {
emit('update:modelValue', selected.value)
})
const handleClick = (option: SelectFieldOption) => {
selectedValue.value = option.value
open.value = false
emit('update:modelValue', option.value)
}
const emit = defineEmits(['update:modelValue'])
</script>
1 change: 1 addition & 0 deletions src/components/CTA/SelectField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './SelectField.vue';
2 changes: 1 addition & 1 deletion src/components/Containment/ChipContainer/ChipContainer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
class="flex h-[22px] min-w-[69px] max-w-[95px] items-center justify-center justify-between gap-2 overflow-hidden rounded-lg border-[0.25px] border-primary-moonstone bg-primary-light bg-opacity-10 px-2 py-1 text-2 font-normal leading-5 text-primary-moonstone"
class="flex h-[22px] min-w-[69px] max-w-[95px] items-center justify-between gap-2 overflow-hidden rounded-lg border-[0.25px] border-primary-moonstone bg-primary-light bg-opacity-10 px-2 py-1 text-2 font-normal leading-5 text-primary-moonstone"
:class="setIconPosition"
>
<div class="flex cursor-default overflow-hidden overflow-ellipsis whitespace-nowrap">
Expand Down
17 changes: 16 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
module.exports = {
content: ['./src/**/*.vue'],
presets: [require('./src/tailwind/preset.js')]
presets: [require('./src/tailwind/preset.js')],
theme: {
extend: {
fontFamily: {
inter: ['Inter', 'sans-serif'],
eina1: ['Eina1', 'sans-serif']
},
fontWeight: {
500: '500',
700: '700',
800: '800',
medium: '500',
bold: '700'
}
}
}
}

0 comments on commit 2eaa603

Please sign in to comment.