-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
840ed78
946337a
044427b
5668b37
5079d60
900007b
79e2aba
a1bf44b
93a5928
ee54012
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @fiscozen/layout | ||
|
||
TODO |
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' | ||
] | ||
} | ||
] | ||
} |
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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import fiscozenPrettierConfig from '@fiscozen/prettier-config'; | ||
|
||
export default { | ||
...fiscozenPrettierConfig | ||
}; |
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> | ||
</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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just return those strings. no need for res There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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() | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}) |
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' |
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 } |
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"] | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.