Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component/creation-bouton #21

Closed
wants to merge 12 commits into from
13 changes: 13 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<style>
@font-face {
font-family: 'roboto';
src: url('/fonts/roboto-regular.woff2?#iefix') format('woff2'),
url('/fonts/roboto-regular.woff') format('woff'),
url('/fonts/roboto-regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
html body *{
font-family: roboto, sans-serif;
}
</style>
4,597 changes: 804 additions & 3,793 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"vite-plugin-css-injected-by-js": "^3.4.0",
"@vitejs/plugin-vue": "^5.0.4",
"@fortawesome/fontawesome-free": "^6.6.0",
"@tsconfig/node20": "^20.1.2",
"@vue/tsconfig": "^0.5.1",
"vue": "^3.4.21"
Expand Down
Binary file added public/fonts/roboto-regular.ttf
Binary file not shown.
Binary file added public/fonts/roboto-regular.woff
Binary file not shown.
Binary file added public/fonts/roboto-regular.woff2
Binary file not shown.
6 changes: 3 additions & 3 deletions src/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ body {
background-color 0.5s;
line-height: 1.6;
font-family:
Roboto,
Oxygen,
Ubuntu,
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
Expand Down
1 change: 1 addition & 0 deletions src/assets/main.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './base.css';
@import '../tokens/colors.css';

#app {
max-width: 1280px;
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Button from '@/stories/Button.vue'
import Header from '@/stories/Header.vue'
import '@fortawesome/fontawesome-free/css/all.min.css'

export {Button, Header}
36 changes: 27 additions & 9 deletions src/stories/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ const meta = {
tags: ['autodocs'],
argTypes: {
size: { control: 'select', options: ['small', 'medium', 'large'] },
backgroundColor: { control: 'color' },
variant: { options: ['contained', 'outlined', 'subtle'] },
type: { options: ['primary', 'destructive'] },
label: {
options: ['Sans icone', 'Icone droite', 'Icone gauche'],
mapping: {
'Sans icone': { text: 'Button' },
'Icone droite': { text: 'Button', icon: { name: 'fa fa-smile', position: 'right' } },
'Icone gauche': { text: 'Button', icon: { name: 'fa fa-smile', position: 'left' } },
},
}
},
args: {
primary: false,
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
onClick: fn(),
},
Expand All @@ -28,28 +36,38 @@ type Story = StoryObj<typeof meta>;
*/
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
type: 'primary',
label: {
text: 'Button'
},
},
};

export const Secondary: Story = {
export const Destructive: Story = {
args: {
primary: false,
label: 'Button',
type: 'destructive',
label: {
text: 'Button'
},
},
};


export const Large: Story = {
args: {
label: 'Button',
label: {
text: 'Button'
},
size: 'large',
},
};

export const Small: Story = {
args: {
label: 'Button',
label: {
text: 'Button'
},
size: 'small',
},
};

86 changes: 37 additions & 49 deletions src/stories/Button.vue
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
<template>
<button type="button" :class="classes" @click="onClick" :style="style">{{ label }} </button>
<button type="button" :class="classes" @click="onClick" :disabled="disabled">
{{ label.text }}
<i v-if="label.icon" :class="label.icon.name"></i>
</button>
</template>

<script lang="ts" setup>

import { computed } from 'vue';
import "@/tokens/colors.css";
import "@/stories/button.css"
import "@fortawesome/fontawesome-free/css/all.min.css"

type Icon = {
name: string,
position: 'left' | 'right',
}

const props = withDefaults(defineProps<{
type ButtonProps = {
/**
* The label of the button
*/
label: string,
label: {
text: string,
icon?: Icon
},
/**
* primary or secondary button
* Button type
*/
primary?: boolean,
type?: 'primary' | 'destructive',

/**
* Button variant
*/
variant?: 'contained' | 'outlined' | 'subtle',

/**
* size of the button
*/
size?: 'small' | 'medium' | 'large',

/**
* background color of the button
* Button disabled state
*/
backgroundColor?: string,
disabled?: boolean
}

}>(), { primary: false });
const props = withDefaults(defineProps<ButtonProps>(), {
type:'primary',
variant:'contained',
size:'medium',
});

const emit = defineEmits<{
(e: 'click', id: number): void;
}>();

const classes = computed(() => ({
'storybook-button': true,
'storybook-button--primary': props.primary,
'storybook-button--secondary': !props.primary,
[`storybook-button--${props.type || 'primary'}-${props.variant || 'contained'}`]: true,
[`storybook-button--${props.size || 'medium'}`]: true,
}));
[`storybook-button-icon--${props.label.icon?.position}`]: props.label.icon,

const style = computed(() => ({
backgroundColor: props.backgroundColor
}));

const onClick = () => {
Expand All @@ -46,39 +70,3 @@ const onClick = () => {

</script>

<style scoped>
button {
color: red;
}
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
cursor: pointer;
display: inline-block;
line-height: 1;
}
.storybook-button--primary {
color: white;
background-color: #1ea7fd;
}
.storybook-button--secondary {
color: #333;
background-color: transparent;
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
}
.storybook-button--small {
font-size: 12px;
padding: 10px 16px;
}
.storybook-button--medium {
font-size: 14px;
padding: 11px 20px;
}
.storybook-button--large {
font-size: 16px;
padding: 12px 24px;
}

</style>
6 changes: 3 additions & 3 deletions src/stories/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</div>
<div>
<span class="welcome" v-if="user">Welcome, <b>{{ user.name }}</b>!</span>
<my-button size="small" @click="$emit('logout')" label="Log out" v-if="user" />
<my-button size="small" @click="$emit('login')" label="Log in" v-if="!user" />
<my-button primary size="small" @click="$emit('createAccount')" label="Sign up" v-if="!user" />
<my-button size="small" @click="$emit('logout')" :label="{text: 'Log out'}" v-if="user" />
<my-button size="small" @click="$emit('login')" :label="{text: 'Log in'}" v-if="!user" />
<my-button primary size="small" @click="$emit('createAccount')" :label="{text: 'Sign up'}" v-if="!user" />
</div>
</div>
</header>
Expand Down
Loading
Loading