Skip to content

Commit

Permalink
Merge pull request #504 from 3YOURMIND/add-zod/add-make-props
Browse files Browse the repository at this point in the history
add-zod(5): Add makeProps
  • Loading branch information
carsoli committed Sep 24, 2021
2 parents 9e0bad2 + d283c56 commit e06834b
Show file tree
Hide file tree
Showing 24 changed files with 1,214 additions and 253 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ module.exports = {
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: {
'sonarjs/no-duplicate-string': 'off',
'no-console': 'off',
'import/order': [
'warn',
{
Expand All @@ -83,6 +81,10 @@ module.exports = {
'newlines-between': 'always',
},
],
'no-console': 'off',
'no-magic-numbers': 'off',
'sonarjs/no-duplicate-string': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
moduleFileExtensions: ['js', 'json', 'ts', 'vue', 'tsx', 'jsx'],
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: 'tests.ts',
testRegex: '(.*.test.ts)|(tests.ts)',
transform: {
'.*\\.(vue)$': 'vue-jest',
'^.+\\.tsx?$': 'ts-jest',
Expand Down
46 changes: 20 additions & 26 deletions packages/documentation/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
</template>

<script lang="ts">
import { Yoco } from '@3yourmind/yoco'
import { Kotti } from '@3yourmind/kotti-ui'
import { defineComponent, ref } from '@vue/composition-api'
import { Route } from 'vue-router'
import navLogo from '../assets/img/nav_logo.svg'
import { menu } from '../data/menu'
Expand All @@ -44,6 +43,7 @@ export default defineComponent({
setup() {
const route = useRoute()
const router = useRouter()
const isNarrow = ref<boolean>(
(() => {
try {
Expand All @@ -62,8 +62,8 @@ export default defineComponent({
)
return {
handleLinkClick(link: Route) {
router.value.push(link.path)
handleLinkClick(link: Kotti.Navbar.SectionLink & { to: string }) {
router.value.push(link.to)
},
isNarrow,
navLogo,
Expand All @@ -86,28 +86,22 @@ export default defineComponent({
},
],
sections: menu.map(
(
section,
): {
title: string | null
links: Array<{
icon: Yoco.Icon
title: string
path: string
isActive: boolean
}>
} => ({
links: section.subsections.map((subsection) => ({
icon: subsection.icon,
title: subsection.title,
path: `/${subsection.path}${
subsection.pages.length >= 1 ? `/${subsection.pages[0].path}` : ''
}`,
isActive:
subsection.path === ''
? route.value.path === '/'
: route.value.path.startsWith(`/${subsection.path}`),
})),
(section): Kotti.Navbar.Section => ({
links: section.subsections.map(
(subsection): Kotti.Navbar.SectionLink & { to: string } => ({
icon: subsection.icon,
isActive:
subsection.path === ''
? route.value.path === '/'
: route.value.path.startsWith(`/${subsection.path}`),
title: subsection.title,
to: `/${subsection.path}${
subsection.pages.length >= 1
? `/${subsection.pages[0].path}`
: ''
}`,
}),
),
title: section.title,
}),
),
Expand Down
34 changes: 18 additions & 16 deletions packages/documentation/pages/examples/layouts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,52 +66,53 @@ export default {
{
links: [
{
link: '#',
title: 'Dashboard',
icon: Yoco.Icon.DASHBOARD,
isActive: true,
link: '#',
title: 'Dashboard',
},
{
link: '/usage/layouts/navbar',
title: 'Close Example',
icon: Yoco.Icon.CLOSE,
isActive: true,
link: '/usage/layouts/navbar',
title: 'Close Example',
},
],
title: null,
},
{
title: 'Order Management',
links: [
{
link: '#',
title: 'Orders',
icon: Yoco.Icon.INVOICE,
isActive: false,
link: '#',
title: 'Orders',
},
{
link: '#',
title: 'Quotes',
icon: Yoco.Icon.REQUEST,
isActive: false,
link: '#',
title: 'Quotes',
},
],
title: 'Order Management',
},
{
title: 'Agile MES',
links: [
{
link: '#',
title: 'Parts',
icon: Yoco.Icon.BOX_3D,
isActive: false,
link: '#',
title: 'Parts',
},
{
link: '#',
title: 'Schedule',
icon: Yoco.Icon.CALENDAR,
isActive: false,
link: '#',
title: 'Schedule',
},
],
title: 'Agile MES',
},
],
navbarNotification: {
Expand All @@ -121,7 +122,6 @@ export default {
},
userMenuData: [
{
title: 'Switch To',
links: [
{
link: '#',
Expand All @@ -132,9 +132,9 @@ export default {
title: 'Service Panel',
},
],
title: 'Switch To',
},
{
title: 'Recent Service',
links: [
{
link: '#',
Expand All @@ -149,6 +149,7 @@ export default {
title: '4YOURMIND Service',
},
],
title: 'Recent Service',
},
{
links: [
Expand All @@ -161,6 +162,7 @@ export default {
title: 'Logout (Close Example)',
},
],
title: null,
},
],
actionbarMenu: [
Expand Down
1 change: 1 addition & 0 deletions packages/kotti-ui/.unimportedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extensions": [".js", ".jsx", ".ts", ".tsx", ".vue"],
"ignorePatterns": ["**/node_modules/**", "**/dist/**"],
"ignoreUnimported": [
"**/*.test.ts",
"**/tests.ts",
"**/*.d.ts",
"**/tokens/**",
Expand Down
3 changes: 2 additions & 1 deletion packages/kotti-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"normalize.css": "^8.0.1",
"tippy.js": "6.x",
"ts-custom-error": "^3.1.1",
"vue-clickaway": "^2.2.2"
"vue-clickaway": "^2.2.2",
"zod": "^3.8.2"
},
"description": "Kotti Vue Component UI",
"devDependencies": {
Expand Down
16 changes: 3 additions & 13 deletions packages/kotti-ui/source/kotti-banner/KtBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
</template>

<script lang="ts">
import { isYocoIcon, Yoco } from '@3yourmind/yoco'
import { Yoco } from '@3yourmind/yoco'
import { computed, defineComponent, ref } from '@vue/composition-api'
import { KtButton } from '../kotti-button'
import { useTranslationNamespace } from '../kotti-translation/hooks'
import { makeProps } from '../make-props'
import { KottiBanner } from './types'
Expand All @@ -31,18 +32,7 @@ export default defineComponent<KottiBanner.PropsInternal>({
components: {
KtButton,
},
props: {
actionText: { default: null, type: String },
expandCloseLabel: { default: null, type: String },
expandLabel: { default: null, type: String },
icon: {
default: Yoco.Icon.ANNOUNCE,
type: String,
validator: isYocoIcon,
},
isGray: { default: false, type: Boolean },
message: { required: true, type: String },
},
props: makeProps(KottiBanner.propsSchema),
setup(props, { slots }) {
const translations = useTranslationNamespace('KtBanner')
Expand Down
24 changes: 12 additions & 12 deletions packages/kotti-ui/source/kotti-banner/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Yoco } from '@3yourmind/yoco'

import { SpecifyRequiredProps } from '../types/utilities'
import { Yoco, yocoIconSchema } from '@3yourmind/yoco'
import { z } from 'zod'

export namespace KottiBanner {
export type PropsInternal = {
actionText: string | null
icon: Yoco.Icon
isGray: boolean
message: string
expandCloseLabel: string | null
expandLabel: string | null
}
export const propsSchema = z.object({
actionText: z.string().nullable().default(null),
expandCloseLabel: z.string().nullable().default(null),
expandLabel: z.string().nullable().default(null),
icon: yocoIconSchema.default(Yoco.Icon.ANNOUNCE),
isGray: z.boolean().default(false),
message: z.string(),
})

export type Props = SpecifyRequiredProps<PropsInternal, 'message'>
export type PropsInternal = z.output<typeof propsSchema>
export type Props = z.input<typeof propsSchema>

export type Translations = {
expandCloseLabel: string
Expand Down
40 changes: 3 additions & 37 deletions packages/kotti-ui/source/kotti-breadcrumb/KtBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,15 @@
</template>

<script lang="ts">
import { isYocoIcon, Yoco } from '@3yourmind/yoco'
import { defineComponent } from '@vue/composition-api'
import { isBoolean, isFunction, isString } from 'lodash'
import { KottiBreadcrumb } from './types'
import { makeProps } from '../make-props'
const breadcrumbValidator = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
): value is KottiBreadcrumb.Breadcrumb =>
value !== null &&
typeof value === 'object' &&
isBoolean(value.isCompleted) &&
isString(value.title) &&
isFunction(value.onClick)
import { KottiBreadcrumb } from './types'
export default defineComponent<KottiBreadcrumb.PropsInternal>({
name: 'KtBreadcrumb',
props: {
breadcrumbs: {
type: Array,
required: true,
validator: (value: unknown): value is Array<KottiBreadcrumb.Breadcrumb> =>
Array.isArray(value) && value.every(breadcrumbValidator),
},
separator: {
type: Object,
default: (): KottiBreadcrumb.Style => ({
style: KottiBreadcrumb.SeparatorType.ICON,
value: Yoco.Icon.CHEVRON_RIGHT,
}),
validator: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
): value is KottiBreadcrumb.Props['separator'] =>
value !== null &&
typeof value === 'object' &&
((value.style === KottiBreadcrumb.SeparatorType.ICON &&
isYocoIcon(value.value)) ||
(value.style === KottiBreadcrumb.SeparatorType.TEXT &&
isString(value.value))),
},
},
props: makeProps(KottiBreadcrumb.propsSchema),
setup(props) {
return {
handleClick: (item: KottiBreadcrumb.Breadcrumb) => {
Expand Down

0 comments on commit e06834b

Please sign in to comment.