Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/lib 1271 fzlayout #174

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@fiscozen/dropdown": "workspace:^",
"@fiscozen/icons": "workspace:^",
"@fiscozen/input": "workspace:^",
"@fiscozen/layout": "workspace:^",
"@fiscozen/link": "workspace:^",
"@fiscozen/navbar": "workspace:^",
"@fiscozen/navlink": "workspace:^",
Expand Down
170 changes: 170 additions & 0 deletions apps/storybook/src/stories/Layout.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import type { Meta, StoryObj } from '@storybook/vue3'
import { FzLayout, FzLayoutProps } from '@fiscozen/layout'

const meta: Meta<typeof FzLayout> = {
title: '@fiscozen/layout/FzLayout',
component: FzLayout,
tags: ['autodocs'],
argTypes: {},
args: {},
decorators: [
() => ({
template: `
<div class="opacity">
<div>
<story />
</div>
</div>
`
})
]
}

const leftShoulder = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<div class="w-full h-full bg-red-100"></div>
<div class="w-full h-full bg-green-100"></div>
</FzLayout>
`
})

export const LeftShoulder = {
render: leftShoulder,
args: {
layout: 'leftShoulder'
}
}

const twoColumns = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<div class="w-full h-full bg-red-100"></div>
<div class="w-full h-full bg-green-100"></div>
</FzLayout>
`
})

export const TwoColumns = {
render: twoColumns,
args: {
layout: 'twoColumns'
}
}


const multipleRows = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<div class="w-full h-full bg-red-100"></div>
<div class="w-full h-full bg-green-100"></div>
<div class="w-full h-full bg-orange-200"></div>
<div class="w-full h-full bg-cyan-100"></div>
</FzLayout>
`
})

const leftShoulderNavbar = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<template #navbar>
<div class="w-full h-full bg-red-100"></div>
</template>
<template #header>
<div class="w-full h-full bg-green-100"></div>
</template>
<template #left-shoulder>
<div class="w-full h-full bg-orange-200"></div>
</template>
<template #default>
<div class="w-full h-full bg-cyan-100"></div>
</template>
</FzLayout>
`
})

export const LeftShoulderNavbar = {
render: leftShoulderNavbar,
args: {
layout: 'leftShoulderNavbar'
}
}

const rightShoulderNavbar = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<template #navbar>
<div class="w-full h-full bg-red-100"></div>
</template>
<template #header>
<div class="w-full h-full bg-green-100"></div>
</template>
<template #right-shoulder>
<div class="w-full h-full bg-orange-200"></div>
</template>
<template #default>
<div class="w-full h-full bg-cyan-100"></div>
</template>
</FzLayout>
`
})

export const RightShoulderNavbar = {
render: rightShoulderNavbar,
args: {
layout: 'rightShoulderNavbar'
}
}

export const MultipleRows = {
render: multipleRows,
args: {
layout: 'multipleRows'
}
}

const squares = (args: FzLayoutProps) => ({
setup() {
return { args }
},
components: {FzLayout},
template: `
<FzLayout v-bind="args">
<div class="w-full h-full bg-red-100"></div>
<div class="w-full h-full bg-green-100"></div>
<div class="w-full h-full bg-orange-200"></div>
<div class="w-full h-full bg-cyan-100"></div>
<div class="w-full h-full bg-slate-100"></div>
<div class="w-full h-full bg-purple-100"></div>
</FzLayout>
`
})

export const Squares = {
render: squares,
args: {
layout: 'squares'
}
}

export default meta
3 changes: 2 additions & 1 deletion apps/storybook/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
"./node_modules/@fiscozen/input/src/**/*.{html,js,ts,vue}",
"./node_modules/@fiscozen/typeahead/src/**/*.{html,js,ts,vue}",
"./node_modules/@fiscozen/datepicker/src/**/*.{html,js,ts,vue}",
"./node_modules/@fiscozen/divider/src/**/*.{html,js,ts,vue}"
"./node_modules/@fiscozen/divider/src/**/*.{html,js,ts,vue}",
"./node_modules/@fiscozen/layout/src/**/*.{html,js,ts,vue}"
],
}
3 changes: 3 additions & 0 deletions packages/layout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @fiscozen/layout

TODO
18 changes: 18 additions & 0 deletions packages/layout/eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': ['@fiscozen/eslint-config', 'plugin:storybook/recommended'],
overrides: [
{
files: [
'cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}',
'cypress/support/**/*.{js,ts,jsx,tsx}'
],
'extends': [
'plugin:cypress/recommended'
]
}
]
}
40 changes: 40 additions & 0 deletions packages/layout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@fiscozen/layout",
"version": "0.1.0",
"description": "Design System Layout component",
"scripts": {
"coverage": "vitest run --coverage",
"format": "prettier --write src/",
"test:unit": "vitest run",
"build": "vue-tsc && vite build"
},
"main": "src/index.ts",
"type": "module",
"keywords": [],
"author": "Riccardo Agnoletto",
"peerDependencies": {
"tailwindcss": "^3.4.1",
"vue": "^3.4.13"
},
"devDependencies": {
"@fiscozen/eslint-config": "workspace:^",
"@fiscozen/prettier-config": "workspace:^",
"@fiscozen/tsconfig": "workspace:^",
"@rushstack/eslint-patch": "^1.3.3",
"@types/jsdom": "^21.1.6",
"@types/node": "^18.19.3",
"@vitejs/plugin-vue": "^4.5.2",
"@vitest/coverage-v8": "^1.2.1",
"@vue/test-utils": "^2.4.3",
"@vue/tsconfig": "^0.5.0",
"eslint": "^8.49.0",
"jsdom": "^23.0.1",
"prettier": "^3.0.3",
"typescript": "~5.3.0",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.8.3",
"vitest": "^1.2.0",
"vue-tsc": "^1.8.25"
},
"license": "MIT"
}
5 changes: 5 additions & 0 deletions packages/layout/prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import fiscozenPrettierConfig from '@fiscozen/prettier-config';

export default {
...fiscozenPrettierConfig
};
75 changes: 75 additions & 0 deletions packages/layout/src/FzLayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<div class="fz-layout w-dvw h-dvh grid gap-10 p-16" :class="layoutClass">
<template v-if="['twoColumns', 'leftShoulder', 'rightShoulderNavbar', 'squares'].includes(props.layout)">
<slot></slot>
</template>
<template v-if="props.layout === 'leftShoulderNavbar'">
<div class="col-span-2">
<slot name="navbar"></slot>
</div>
<div class="col-span-2">
<slot name="header"></slot>
</div>
<div class="col-span-2 lg:col-span-1">
<slot name="left-shoulder"></slot>
</div>
<div class="col-span-2 lg:col-span-1">
<slot></slot>
</div>
</template>
<template v-if="props.layout === 'rightShoulderNavbar'">
<div class="col-span-2">
<slot name="navbar"></slot>
</div>
<div class="col-span-2">
<slot name="header"></slot>
</div>
<div class="col-span-2 lg:col-span-1">
<slot></slot>
</div>
<div class="col-span-2 lg:col-span-1">
<slot name="right-shoulder"></slot>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have a single template for each layout, it's more redundant but makes it more clear and easier to maintain
There's also two default slots for rightShoulderNavbar

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix the double slot. As per the single template, I actually prefer this way at least for "default slot - only" templates.

</template>
</div>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import { FzLayoutProps } from './types'

const props = withDefaults(defineProps<FzLayoutProps>(), {})

const emit = defineEmits([])

const layoutClass = computed(() => {
let res = '';
switch (props.layout) {
case 'multipleRows':
res = 'grid-rows-auto'
break;
case 'twoColumns':
res = 'grid-cols-1 grid-rows-[60px_1fr] lg:grid-rows-1 lg:grid-cols-2'
break;
case 'leftShoulder':
res = 'grid-rows-[60px_1fr] grid-cols-1 lg:grid-rows-1 lg:grid-cols-[260px_1fr]'
break;
case 'leftShoulderNavbar':
res = 'grid-rows-[40px_160px_60px_1fr] grid-cols-1 lg:grid-rows-[40px_160px_1fr] lg:grid-cols-[260px_1fr]'
break;
case 'rightShoulderNavbar':
res = 'grid-rows-[40px_160px_60px_1fr] grid-cols-1 lg:grid-rows-[40px_160px_1fr] lg:grid-cols-[1fr_260px]'
break;
case 'squares':
res = 'grid-cols-1 grid-rows-auto sm:grid-cols-2 sm:grid-rows-auto md:grid-cols-3 md:grid-rows-auto auto-rows-[332px]'
break;
default:
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just return those strings. no need for res

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much prefer functions to have a single exit if possible, except for quick "out" conditions at the very top when needed.

}
return res;
});

</script>

<style scoped>
</style>
14 changes: 14 additions & 0 deletions packages/layout/src/__tests__/FzLayout.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { FzLayout } from '..'

describe.concurrent('FzLayout', () => {
it('matches snaphost', async ({ expect }) => {
const wrapper = mount(FzLayout, {
props: {},
slots: {}
})

expect(wrapper.html()).toMatchSnapshot()
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add other tests based on the values the layout can take

})
2 changes: 2 additions & 0 deletions packages/layout/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as FzLayout } from './FzLayout.vue'
export type * from './types'
5 changes: 5 additions & 0 deletions packages/layout/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type FzLayoutProps = {
layout: 'twoColumns' | 'multipleRows' | 'leftShoulder' | 'leftShoulderNavbar' | 'rightShoulderNavbar' | 'squares'
}

export { FzLayoutProps }
4 changes: 4 additions & 0 deletions packages/layout/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@fiscozen/tsconfig",
"exclude": ["src/__tests__", "vite.config.ts", "vitest.config.ts"]
}
Loading