Skip to content

Commit d476a44

Browse files
authored
Merge pull request #2 from prolazydev/web
Web
2 parents 3f2d566 + 00317ac commit d476a44

File tree

14 files changed

+645
-285
lines changed

14 files changed

+645
-285
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# vue-m ⚒ WORK IN PROGRESS
22

3-
`0.1.1 is out! 🎉🥳`
43

54
![npm](https://img.shields.io/npm/v/@prolazydev/vue-m?color=blue&label=release&style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@prolazydev/vue-m?color=orange&label=downs&style=for-the-badge) [![license](https://img.shields.io/github/license/prolazydev/vue-m.svg?style=for-the-badge)](https://github.com/prolazydev/vue-m/blob/main/LICENSE) [![npm](https://img.shields.io/badge/-changelog-orange?style=for-the-badge)](https://github.com/prolazydev/vue-m/blob/main/CHANGELOG.md) [![code with hearth by NHN Cloud](https://img.shields.io/badge/%3C%2F%3E%20with%20%20cooless%20%F0%9F%98%8E%20by-prolazydev-00bf76.svg?style=for-the-badge)](https://github.com/nhn)
65

vue-m-ui/package-lock.json

Lines changed: 64 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vue-m-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prolazydev/vue-m",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"private": false,
55
"description": "UI components for Vue.js made with tailwind and ❤",
66
"author": {
Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
2-
<button ref="mBtn" :disabled="handleLoadingState || (disabled as boolean)"
3-
:class="[ !isCustomColor ? handleColor : 'm-btn', handleSize, handleShape, handleTransparency, handleTextColor ]"
4-
:style="isCustomColor ? (handleColor as StyleValue) : ''" >
5-
<div :class="{ 'm-loading': handleLoadingState }" class="m-btn-content">
2+
<button ref="mBtn" :disabled="handleLoadingState || (disabled as boolean)" :class="[ 'm-btn',
3+
handleCustomColors, handleColor, handleSize, handleShape, handleTransparency, handleTextColor,
4+
]">
5+
<div :class="{ 'm-loading': handleLoadingState }" class="m-btn-content">
66
<template v-if="props.text"> {{ props.text }} </template>
77
<slot v-else />
88
</div>
@@ -14,14 +14,12 @@
1414
</template>
1515

1616
<script lang="ts" setup>
17-
import { ComputedRef, StyleValue, computed, ref } from 'vue';
17+
import { StyleValue, computed, ref } from 'vue';
1818
import { createLighterShades, dynamicSVG } from '@/utils';
1919
import { btnSizes, btnColors } from './props';
2020
import { shapes, textColors } from '@/common';
2121
2222
const mBtn = ref<HTMLButtonElement | null>(null);
23-
const shades = ref<string[]>([]);
24-
const mousedown = ref(false);
2523
2624
// TODO: Add tab tab-indexing
2725
const props = defineProps({
@@ -63,65 +61,38 @@ const props = defineProps({
6361
});
6462
6563
// Prop Handling
66-
const handleTextColor= computed<string>(() => {
64+
const handleTextColor = computed<string>(() => {
65+
mBtn.value?.style.removeProperty('--m-btn-text-color');
66+
6767
if (!props.textColor)
6868
return '';
69+
if (props.textColor.startsWith('#') || props.textColor.startsWith('rgb'))
70+
return mBtn.value?.style.setProperty('--m-btn-text-color', props.textColor);
6971
return (textColors as any)[ props.textColor ];
7072
});
7173
7274
const handleColor = computed<string | StyleValue>(() => {
73-
removeEventListeners();
75+
mBtn.value?.style.removeProperty('--m-btn-bg-color');
76+
mBtn.value?.style.removeProperty('--m-btn-bg-color-hover');
77+
mBtn.value?.style.removeProperty('--m-btn-bg-color-active');
78+
7479
if (!props.color)
7580
return btnColors.default + ' ' + btnSizes.md;
76-
if (props.color.startsWith('#') || props.color.startsWith('rgb') || props.color.startsWith('rgba')) {
77-
shades.value = createLighterShades(props.color);
78-
addEventListeners();
81+
if (props.color.startsWith('#') || props.color.startsWith('rgb')) {
82+
const shades = createLighterShades(props.color);
7983
80-
return { backgroundColor: props.color };
84+
mBtn.value?.style.setProperty('--m-btn-bg-color', props.color);
85+
mBtn.value?.style.setProperty('--m-btn-bg-color-hover', shades[ 0 ]);
86+
mBtn.value?.style.setProperty('--m-btn-bg-color-active', shades[ 1 ]);
87+
return;
8188
}
8289
return (btnColors as any)[ props.color ];
8390
});
8491
85-
function removeEventListeners() {
86-
mBtn.value?.removeEventListener('mouseenter', onMouseEnter);
87-
mBtn.value?.removeEventListener('mouseleave', onMouseLeave);
88-
89-
mBtn.value?.removeEventListener('mousedown', onMouseDown);
90-
mBtn.value?.removeEventListener('mouseup', onMouseUp);
91-
92-
mBtn.value?.removeEventListener('keydown', onKeyDown);
93-
94-
mBtn.value?.removeEventListener('focusin', onFocusIn);
95-
mBtn.value?.removeEventListener('blur', onBlur);
96-
}
97-
function addEventListeners() {
98-
mBtn.value?.addEventListener('mouseenter', onMouseEnter);
99-
mBtn.value?.addEventListener('mouseleave', onMouseLeave);
100-
101-
mBtn.value?.addEventListener('mousedown', onMouseDown);
102-
mBtn.value?.addEventListener('mouseup', onMouseUp);
103-
104-
mBtn.value?.addEventListener('keydown', onKeyDown);
105-
106-
mBtn.value?.addEventListener('focusin', onFocusIn);
107-
mBtn.value?.addEventListener('blur', onBlur);
108-
}
109-
const onMouseEnter = () => mBtn.value!.style.backgroundColor = shades.value[ 0 ];
110-
const onMouseLeave = () => mBtn.value!.style.backgroundColor = props.color;
111-
const onMouseDown = () => { mBtn.value!.style.backgroundColor = shades.value[ 1 ]; mousedown.value = true; };
112-
const onMouseUp = () => mBtn.value!.style.backgroundColor = shades.value[ 0 ];
113-
114-
const onKeyDown = (e: KeyboardEvent) => {
115-
if (e.key === 'Shift')
116-
mBtn.value!.style.boxShadow = `0px 0px 0px white, 0px 0px 0px 1.5px ${props.color}`;
117-
}
118-
119-
const onFocusIn = () => {
120-
if (!mousedown.value)
121-
mBtn.value!.style.boxShadow = `0px 0px 0px white, 0px 0px 0px 1.5px ${props.color}`;
122-
mousedown.value = false;
123-
};
124-
const onBlur = () => { mBtn.value!.style.boxShadow = ''; mousedown.value = false; };
92+
const handleCustomColors = computed<string | void>(() => {
93+
if (props.color.startsWith('#') || props.color.startsWith('rgb') || props.textColor.startsWith('#') || props.textColor.startsWith('rgb'))
94+
return 'm-btn-custom-colors';
95+
});
12596
12697
const handleSize = computed(() => {
12798
if (!props.size)
@@ -148,13 +119,4 @@ const handleTransparency = computed(() => {
148119
return 'm-btn-transparent';
149120
});
150121
151-
const isCustomColor: ComputedRef<boolean> = computed(() => {
152-
if (typeof handleColor.value == 'string')
153-
return false;
154-
155-
return typeof handleColor.value == 'object'
156-
&& (handleColor as any).value?.backgroundColor?.startsWith('#')
157-
|| (handleColor as any).value?.backgroundColor?.startsWith('rgb');
158-
})
159-
160122
</script>

0 commit comments

Comments
 (0)