Skip to content

Commit

Permalink
feat(dropdown): added open and close events (#386)
Browse files Browse the repository at this point in the history
## Feat
* feat: added events when closing and opening

## Chore
* chore: project configuration changes
* chore(deps-dev): updated dependencies
* chore: bumped version

## Style
* style: fixed lint issues

## Fix
* fix(button): centered spinner loader

## CI
* ci: moved semantic commit checking to app
  • Loading branch information
nandi95 authored Jan 14, 2022
1 parent b818b0e commit b27cd6f
Show file tree
Hide file tree
Showing 12 changed files with 1,610 additions and 1,909 deletions.
44 changes: 44 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# https://github.com/zeke/semantic-pull-requests#configuration

# Always validate the PR title AND all the commits
titleAndCommits: true

# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowMergeCommits: true

# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowRevertCommits: true

# Scopes matching the ones defined in .commitlintrc.js file
scopes:
- 'avatar'
- 'badge'
- 'button'
- 'button-group'
- 'button-toggle'
- 'checkbox'
- 'dropdown'
- 'file-input'
- 'file-uploader'
- 'input'
- 'loader-linear'
- 'loader-spinner'
- 'modal'
- 'panel'
- 'pill'
- 'radio'
- 'range-slider'
- 'select'
- 'table'
- 'textarea'
- 'toggle'
- 'pagination'
- 'transitions'
- 'tooltip'
- 'outer-html'
- 'click-away'
- 'intersect'
- 'deps'
- 'deps-dev'
17 changes: 0 additions & 17 deletions .github/workflows/commitlint.yml

This file was deleted.

1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
Expand Down
3,403 changes: 1,528 additions & 1,875 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@karnama/vueish",
"version": "0.8.3",
"version": "0.9.0",
"files": [
"dist",
"types"
Expand Down Expand Up @@ -31,15 +31,15 @@
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@commitlint/config-conventional": "^15.0.0",
"@commitlint/prompt-cli": "^15.0.0",
"@commitlint/types": "^15.0.0",
"@commitlint/config-conventional": "^16.0.0",
"@commitlint/prompt-cli": "^16.0.0",
"@commitlint/types": "^16.0.0",
"@types/glob": "^7.1.3",
"@types/jest": "^27.0.2",
"@types/lodash-es": "^4.17.4",
"@types/minimist": "^1.2.1",
"@types/requestidlecallback": "^0.3.1",
"@types/tailwindcss": "^2.0.6",
"@types/tailwindcss": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vitejs/plugin-vue": "^2.0.1",
Expand All @@ -50,7 +50,7 @@
"autoprefixer": "^10.4.0",
"babel-jest": "^27.3.1",
"babel-loader": "^8.2.2",
"commitlint": "^15.0.0",
"commitlint": "^16.0.2",
"eslint": "^8.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^25.2.4",
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/UIButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<slot name="loader">
<UISpinnerLoader v-if="loading"
inherit-color
class="px-4"
class="px-4 mx-auto"
:class="loaderColor"
:stroke="2"
:diameter="25" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/__snapshots__/UIButton.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`UIButton should display the loading correctly 1`] = `
<transition-stub>
<div
class="ui-spinner-loader indeterminate px-4"
class="ui-spinner-loader indeterminate px-4 mx-auto"
role="progressbar"
>
<svg
Expand Down
21 changes: 21 additions & 0 deletions src/components/dropdown/UIDropdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,25 @@ describe('UIDropdown', () => {
expect(wrapper.find('#content').exists()).toBe(true);
expect(wrapper.find('#trigger').exists()).toBe(true);
});

it('should emit the open and close event at appropriate times', () => {
const wrapper = mount(UIDropdown, {
slots: {
default: h('div', { id: 'content' }),
trigger: h('div', { id: 'trigger' })
}
});

expect(wrapper.emitted()).not.toHaveProperty('open');
expect(wrapper.emitted()).not.toHaveProperty('close');

// @ts-expect-error - ts reckons this has the type never
wrapper.vm.toggle();
expect(wrapper.emitted('open')).toHaveLength(1);
expect(wrapper.emitted()).not.toHaveProperty('close');

// @ts-expect-error - ts reckons this has the type never
wrapper.vm.toggle();
expect(wrapper.emitted('close')).toHaveLength(1);
});
});
7 changes: 6 additions & 1 deletion src/components/dropdown/UIDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export default defineComponent({
}
},
setup(props) {
emits: ['open', 'close'],
setup(props, ctx) {
const isOpen = ref(false);
const uiDropdown = ref<HTMLDivElement>();
const dropdown = ref<HTMLDivElement>();
Expand Down Expand Up @@ -144,12 +146,15 @@ export default defineComponent({
if (event && props.atMousePosition) {
mousePos.x = event.offsetX;
mousePos.y = event.offsetY;
} else {
ctx.emit('open');
}
isOpen.value = true;
};
const hide = () => {
isOpen.value = false;
ctx.emit('close');
};
const toggle = (event?: MouseEvent) => {
// If the dropdown is showing via contextmenu event, and the user has triggered
Expand Down
4 changes: 2 additions & 2 deletions src/demo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createApp, defineAsyncComponent } from 'vue';
import { createApp } from 'vue';
import DemoBoard from './DemoBoard.vue';
import { createRouter, createWebHistory } from 'vue-router';
import './assets/styles/main.scss';
Expand All @@ -23,7 +23,7 @@ const routes = Object.keys(demos)

return {
path: '/' + getPath(path),
component: defineAsyncComponent(async () => demos[path]()),
component: async () => demos[path](),
meta: {
label: getPath(path).replace('-', ' '),
type: isDirective ? 'Directives' : 'Components'
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/cache/LocalCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class LocalCache {
*
* @return {*}
*/
public get<T>(key: string, defaultValue?: T): T
public get<T>(key: string, defaultValue?: T): T;
public get(key: string, defaultValue?: unknown): undefined {
try {
let value = JSON.parse(localStorage.getItem(this.prefix + key) as string);
Expand Down
4 changes: 0 additions & 4 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import defaultSettings from '@/defaultSettings';
import type { ComponentPublicInstance } from 'vue';

beforeAll(() => {
if (process.env.IS_CI) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
config.global.config.warnHandler = () => {};
}
config.global.config.globalProperties = {
// eslint-disable-next-line @typescript-eslint/naming-convention
Vueish: defaultSettings
Expand Down

0 comments on commit b27cd6f

Please sign in to comment.