generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 186: add counter component * 186: fix format * Update src/components/Form/MucCounter.vue Co-authored-by: Fabian Wilms <[email protected]> * 186: pr feedback --------- Co-authored-by: Fabian Wilms <[email protected]>
- Loading branch information
1 parent
cf90215
commit f6b4d37
Showing
4 changed files
with
179 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import MucCounter from "./MucCounter.vue"; | ||
|
||
export default { | ||
component: MucCounter, | ||
title: "Forms/MucCounter", | ||
tags: ["autodocs"], | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: `The MucCounter offers the functionality of a simple counter. | ||
[🔗 Patternlab-Docs](https://patternlab.muenchen.space/?p=elements-combobox) | ||
`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
modelValue: 0, | ||
label: "This is a label", | ||
}, | ||
}; | ||
|
||
export const MinAndMax = { | ||
args: { | ||
...Default.args, | ||
modelValue: 2, | ||
min: 2, | ||
max: 10, | ||
}, | ||
}; | ||
|
||
export const Link = { | ||
args: { | ||
...Default.args, | ||
link: "#", | ||
}, | ||
}; | ||
|
||
export const Disabled = { | ||
args: { | ||
...Default.args, | ||
disabled: true, | ||
}, | ||
}; |
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,128 @@ | ||
<template> | ||
<div class="wrapper"> | ||
<MucButton | ||
v-on:click="clickedMinus" | ||
variant="secondary" | ||
:disabled="disableMinus" | ||
> | ||
<template #default><muc-icon icon="minus" /></template> | ||
</MucButton> | ||
<p> | ||
<strong | ||
class="centered-text" | ||
style="color: var(--color-brand-main-blue)" | ||
> | ||
{{ modelValue }} | ||
</strong> | ||
</p> | ||
<MucButton | ||
v-on:click="clickedPlus" | ||
variant="secondary" | ||
:disabled="disablePlus" | ||
> | ||
<template #default><muc-icon icon="plus" /></template> | ||
</MucButton> | ||
<p v-if="link"> | ||
<label class="centered-text"> | ||
<muc-link | ||
:label="label" | ||
:href="link" | ||
></muc-link> | ||
</label> | ||
</p> | ||
|
||
<p v-else> | ||
<label class="centered-text"> | ||
{{ label }} | ||
</label> | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from "vue"; | ||
import { MucButton } from "../Button"; | ||
import { MucIcon } from "../Icon"; | ||
import { MucLink } from "../Link"; | ||
/** | ||
* Input value from the counter component. | ||
*/ | ||
const modelValue = defineModel<number>({ default: 0 }); | ||
const props = withDefaults( | ||
defineProps<{ | ||
/** | ||
* Label shown after the counter | ||
*/ | ||
label: string; | ||
/** | ||
* Optional minimum of counter | ||
*/ | ||
min?: number; | ||
/** | ||
* Optional maximum of counter | ||
*/ | ||
max?: number; | ||
/** | ||
* Optional link for label | ||
*/ | ||
link?: string; | ||
/** | ||
* Optionally disable this specific counter | ||
*/ | ||
disabled?: boolean; | ||
}>(), | ||
{ | ||
disabled: false, | ||
} | ||
); | ||
/** | ||
* Function increases the value of modelValue by 1 | ||
*/ | ||
const clickedPlus = () => modelValue.value++; | ||
/** | ||
* Function decreases the value of modelValue by 1 | ||
*/ | ||
const clickedMinus = () => modelValue.value--; | ||
/** | ||
* Computed property if this plus button should be disabled | ||
*/ | ||
const disablePlus = computed( | ||
() => (!!props.max && !(modelValue.value < props.max)) || props.disabled | ||
); | ||
/** | ||
* Computed property if this minus button should be disabled | ||
*/ | ||
const disableMinus = computed( | ||
() => | ||
modelValue.value == 0 || | ||
(!!props.min && !(modelValue.value > props.min)) || | ||
props.disabled | ||
); | ||
</script> | ||
|
||
<style scoped> | ||
.wrapper { | ||
display: flex; | ||
} | ||
.wrapper > * { | ||
margin: 0 8px; | ||
} | ||
.centered-text { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
} | ||
</style> |
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