Skip to content

Commit

Permalink
Standardies labels (#288)
Browse files Browse the repository at this point in the history
## Style
* style: update DemoBoard bg color
* style(input): moved password toggle into the input


## Chore
* chore(dev-deps): Updated commit linting dependencies
- @commitlint/config-conventional
- @commitlint/prompt-cli
- @commitlint/types
- commitlint
* chore(deps-dev): updated vue

## Feature
* feat: added conditional label rendering
* chore(deps-dev): updated dependencies

## ci
* ci: decrease dependency check frequency
* ci: set action version to major only
* ci: fixed enum

## Test
* test: updated snapshots

## Revert
* revert(file-input): removed the replication attempt code
  • Loading branch information
nandi95 authored Sep 28, 2021
1 parent 86e9ba0 commit 0655bfc
Show file tree
Hide file tree
Showing 31 changed files with 843 additions and 2,904 deletions.
2 changes: 1 addition & 1 deletion .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
'click-away',
'intersect',
'deps',
'dev-deps'
'deps-dev'
]
],
}
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ updates:
- package-ecosystem: npm
directory: '/'
schedule:
interval: weekly
interval: monthly
time: '00:00'
open-pull-requests-limit: 10
commit-message:
Expand Down
3,376 changes: 625 additions & 2,751 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@karnama/vueish",
"version": "0.7.0",
"version": "0.7.1",
"files": [
"dist",
"types"
Expand All @@ -19,7 +19,6 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"watch": "vite build --watch",
"test": "jest",
"test:update-snapshots": "npm run test -- --updateSnapshot",
"lint": "eslint . --fix --ext .ts,.vue,.tsx",
Expand All @@ -32,9 +31,9 @@
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@commitlint/config-conventional": "^12.1.4",
"@commitlint/prompt-cli": "^12.1.4",
"@commitlint/types": "^12.1.4",
"@commitlint/config-conventional": "^13.1.0",
"@commitlint/prompt-cli": "^13.1.0",
"@commitlint/types": "^13.1.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.23",
"@types/lodash-es": "^4.17.4",
Expand All @@ -44,15 +43,13 @@
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.26.1",
"@vitejs/plugin-vue": "^1.2.2",
"@vue/compiler-sfc": "~3.0.11",
"@vue/compiler-sfc": "^3.2.11",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/test-utils": "^2.0.0-rc.10",
"@vuedx/typecheck": "^0.7.4",
"@vuedx/typescript-plugin-vue": "^0.7.4",
"autoprefixer": "^10.2.3",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"commitlint": "^12.1.4",
"commitlint": "^13.1.0",
"eslint": "^7.28.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
Expand All @@ -71,7 +68,7 @@
"ts-node": "^10.0.0",
"typescript": "^4.3.4",
"vite": "^2.4.1",
"vue": "~3.0.11",
"vue": "^3.2.11",
"vue-docgen-api": "^4.40.0",
"vue-jest": "^5.0.0-alpha.7",
"vue-loader": "^16.2.0",
Expand Down
13 changes: 13 additions & 0 deletions src/DemoBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,25 @@ export default defineComponent({
});
const isOpen = ref(cache.get('menuOpen', true));
const setBg = (dark: boolean) => {
if (dark) {
document.body.classList.add('bg-gray-700');
document.body.classList.remove('bg-gray-100');
return;
}
document.body.classList.remove('bg-gray-700');
document.body.classList.add('bg-gray-100');
};
document.body.classList.add(cache.get('theme', 'light')!);
setBg(cache.get('theme', 'light') === 'dark');
watch(() => isOpen.value, val => cache.set('menuOpen', val));
watch(() => darkMode.value, val => {
cache.set('theme', val ? 'dark' : 'light');
document.body.classList.toggle('dark');
setBg(val);
});
return {
Expand Down
3 changes: 1 addition & 2 deletions src/components/avatar/__snapshots__/UIAvatar.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

exports[`UIAvatar should correctly display 1`] = `
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
>
<span>
Expand Down
15 changes: 5 additions & 10 deletions src/components/avatar/__snapshots__/UIAvatarGroup.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ exports[`UIAvatarGroup should correctly display 1`] = `
>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
style="z-index: 50;"
>
Expand All @@ -37,8 +36,7 @@ exports[`UIAvatarGroup should correctly display 1`] = `
</div>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
style="z-index: 40;"
>
Expand All @@ -48,8 +46,7 @@ exports[`UIAvatarGroup should correctly display 1`] = `
</div>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
style="z-index: 30;"
>
Expand All @@ -59,17 +56,15 @@ exports[`UIAvatarGroup should correctly display 1`] = `
</div>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full"
style="z-index: 20;"
>
<img
src="imgSource"
/>
</div>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded"
style="z-index: 10;"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ exports[`UICheckbox should correctly display 1`] = `
type="checkbox"
/>
<span
class="ui-checkbox rounded flex justify-center items-center flex-shrink-0
transition-all text-white border-2 cursor-pointer"
class="ui-checkbox rounded flex justify-center items-center flex-shrink-0 transition-all text-white border-2 cursor-pointer"
>
<span
class="transition-all opacity-0 scale-0 text-white"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ exports[`UIDropdown should correctly display 1`] = `
/>
<div
class="dropdown absolute z-50 rounded overflow-scroll flex flex-col items-stretch shadow-lg
bg-white dark:bg-gray-600 ring-1 ring-opacity-5 ring-black dark:ring-white dark:ring-opacity-5"
class="dropdown absolute z-50 rounded overflow-scroll flex flex-col items-stretch shadow-lg bg-white dark:bg-gray-600 ring-1 ring-opacity-5 ring-black dark:ring-white dark:ring-opacity-5"
role="group"
style="max-height: 35vh; width: 250px; right: 0px; top: 0px;"
>
Expand Down
15 changes: 10 additions & 5 deletions src/components/file-input/UIFileInput.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<template>
<div class="ui-file-input" :class="$attrs.class">
<label :for="$attrs.id ?? name"
class="font-medium text-color flex items-center"
:class="{ 'text-color-error': error || $slots.error }">
{{ label }}
</label>
<UIExpandTransition>
<label v-if="label || $slots.label"
:for="$attrs.id ?? name"
class="font-medium text-color flex items-center"
:class="{ 'text-color-error': error || $slots.error }">
<slot name="label">
{{ label }}
</slot>
</label>
</UIExpandTransition>

<div ref="input"
class="rounded flex justify-between items-center shadow-sm focus:outline-none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ exports[`UIFile should display correctly 1`] = `
>
<div
class="ui-avatar text-lg overflow-hidden h-8 w-8
text-white bg-brand-400 flex flex-col justify-center items-center rounded-full avatar text-xs"
class="ui-avatar text-lg overflow-hidden h-8 w-8 text-white bg-brand-400 flex flex-col justify-center items-center rounded-full avatar text-xs"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ exports[`UIFileUploader should display correctly 1`] = `
<div>
<div
aria-label="File Upload"
class="rounded-lg drop-zone border-2 border-dashed transition-colors flex flex-wrap items-stretch
dark:text-white relative border-current"
class="rounded-lg drop-zone border-2 border-dashed transition-colors flex flex-wrap items-stretch dark:text-white relative border-current"
tabindex="0"
>
<input
Expand Down Expand Up @@ -55,8 +54,7 @@ exports[`UIFileUploader should display correctly 1`] = `
</button>
</div>
<div
class="w-full sm:w-1/2 flex flex-col py-6 px-2
justify-between bg-gray-200 dark:bg-gray-600 items-center"
class="w-full sm:w-1/2 flex flex-col py-6 px-2 justify-between bg-gray-200 dark:bg-gray-600 items-center"
style="display: none;"
>
<div
Expand Down
57 changes: 56 additions & 1 deletion src/components/input/UIInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils';
import UIInput from './UIInput.vue';
import { nextTick } from 'vue';

describe('UIInput', () => {
it('should correctly display', () => {
Expand Down Expand Up @@ -59,7 +60,8 @@ describe('UIInput', () => {
const wrapper = mount(UIInput, {
props: {
modelValue: '',
name
name,
label: 'my label'
}
});

Expand Down Expand Up @@ -225,4 +227,57 @@ describe('UIInput', () => {

expect(wrapper.get('.suffix').text()).toBe(suffix);
});

it('should only display the label if slot or prop given', async () => {
let wrapper = mount(UIInput, {
props: {
modelValue: '',
name: 'input'
}
});

expect(wrapper.find('label').exists()).toBe(false);

await wrapper.setProps({ label: 'myLabel' });
expect(wrapper.find('label').exists()).toBe(true);

wrapper = mount(UIInput, {
props: {
modelValue: '',
name: 'input'
},
slots: {
label: 'myLabel'
}
});
expect(wrapper.find('label').exists()).toBe(true);
});

it('should toggle the input type on password type when toggle clicked on', async () => {
jest.useFakeTimers();
const wrapper = mount(UIInput, {
props: {
modelValue: '',
name: 'input',
type: 'password',
passwordToggleTimeout: 1000
}
});

expect(wrapper.get('input').attributes('type')).toBe('password');

await wrapper.get('.pass-toggle').trigger('click');
expect(wrapper.get('input').attributes('type')).toBe('text');

await wrapper.get('.pass-toggle').trigger('click');
expect(wrapper.get('input').attributes('type')).toBe('password');

// it automatically turns back
await wrapper.get('.pass-toggle').trigger('click');
jest.runAllTimers();
await nextTick();
expect(wrapper.get('input').attributes('type')).toBe('password');

jest.useRealTimers();
});
});
37 changes: 21 additions & 16 deletions src/components/input/UIInput.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<template>
<div class="ui-text" :class="$attrs.class">
<label :for="$attrs.id ?? name"
class="font-medium text-color inline-flex"
:class="{ 'text-color-error': error || $slots.error }">
{{ label }}
<template v-if="isPasswordInitially && !disablePasswordToggle">
<button v-if="inputType === 'password'"
class="ml-2"
@click="inputType = 'text'"
v-html="hideIcon" />
<button v-else
class="ml-2"
@click="inputType = 'password'"
v-html="showIcon" />
</template>
</label>
<UIExpandTransition>
<label v-if="label || $slots.label"
:for="$attrs.id ?? name"
class="font-medium text-color inline-flex"
:class="{ 'text-color-error': error || $slots.error }">
<slot name="label">
{{ label }}
</slot>
</label>
</UIExpandTransition>

<div class="shadow-sm dark:shadow-md border border-gray-300 dark:border-gray-500 rounded
bg-white dark:bg-gray-600 transition"
Expand All @@ -25,6 +20,16 @@
}"
:style="$attrs.style">
<div class="flex items-center">
<template v-if="isPasswordInitially && !disablePasswordToggle">
<button v-if="inputType === 'password'"
class="ml-3 -mr-1 p-1 text-color-muted pass-toggle"
@click="inputType = 'text'"
v-html="hideIcon" />
<button v-else
class="ml-3 -mr-1 p-1 text-color-muted pass-toggle"
@click="inputType = 'password'"
v-html="showIcon" />
</template>
<span v-if="prefix ?? $slots.prefix"
class="prefix ml-3 -mr-1 select-none text-color-muted"
:class="{ 'ml-5 -mr-4': large }">
Expand Down Expand Up @@ -357,7 +362,7 @@ input:disabled[type=number] {
-moz-appearance: textfield;
}
.prefix, .suffix {
.prefix, .suffix, .pass-toggle {
line-height: 1.28;
}
</style>
18 changes: 7 additions & 11 deletions src/components/input/__snapshots__/UIInput.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ exports[`UIInput should correctly display 1`] = `
<div
class="ui-text"
>
<label
class="font-medium text-color inline-flex"
for="input"
>
<!--v-if-->
</label>
<transition-stub>
</transition-stub>
<div
class="shadow-sm dark:shadow-md border border-gray-300 dark:border-gray-500 rounded
bg-white dark:bg-gray-600 transition focus-within:border-blue-400 dark:focus-within:border-blue-500"
class="shadow-sm dark:shadow-md border border-gray-300 dark:border-gray-500 rounded bg-white dark:bg-gray-600 transition focus-within:border-blue-400 dark:focus-within:border-blue-500"
>
<div
class="flex items-center"
>
<!--v-if-->
<!--v-if-->
<input
class="flex-1 p-3.5 appearance-none bg-transparent outline-none
text-color disabled:text-gray-400"
class="flex-1 p-3.5 appearance-none bg-transparent outline-none text-color disabled:text-gray-400"
id="input"
name="input"
type="text"
Expand Down
Loading

0 comments on commit 0655bfc

Please sign in to comment.