Skip to content

Commit

Permalink
Merge pull request #874 from hit-pay/new-sidebar-ui
Browse files Browse the repository at this point in the history
feat:added new UI sidebar
  • Loading branch information
kewcoder authored Jan 6, 2025
2 parents eee33bf + d741c3a commit 2f4db9f
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 126 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@orchidui/core",
"description": "Orchid UI, Library Vue 3 tailwind css",
"version": "1.1.31-8",
"version": "1.1.31-9",
"type": "module",
"scripts": {
"build": "vite build"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Elements/Sidebar/HitpaySidebar.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const PAYMENTS_SIDEBAR_GROUP = [
},
{
name: 'others',
label: '',
label: 'Others',
items: PAYMENTS_OTHERS_SIDEBAR_ITEMS
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Elements/Sidebar/OcAccountSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defineProps({
background: linear-gradient(90deg, #ffc83c, #e027fe, #2771fe);
}
$default-size: 40px;
$default-size: 30px;
@mixin size($width, $height) {
height: $height;
Expand Down
36 changes: 36 additions & 0 deletions packages/core/src/Elements/Sidebar/OcAccountSetupProgress.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div class="border relative z-10 border-oc-gray-200 shadow-normal bg-white rounded p-2 flex flex-col gap-y-2">
<div class="py-2 px-3 gap-x-3 flex items-center">
<div class="text-oc-warning flex-1">Finish your account ({{ value }}%)</div>
<Icon name="arrow-top-right" class="text-oc-text-300 hover:text-oc-text" width="14" height="14" @click="$emit('redirect')" />
</div>

<div class="px-3 pb-3 flex flex-col gap-y-3">
<div class="relative bg-oc-accent-1-50 rounded-full h-2">
<div class="absolute top-0 left-0 bg-oc-primary rounded-full h-2" :style="{ width: `${value}%` }"></div>
</div>
<div class="flex items-center gap-x-3">
<div class="w-[6px] h-[6px] bg-oc-success shadow-[0_0_0_4px_var(--oc-success-50)] rounded-full" />
<span class="text-sm text-oc-text-400">{{ infoLabel }}</span>
</div>
</div>

</div>
</template>

<script setup>
import { Icon } from '@/orchidui-core'
defineProps({
value: {
type: Number,
default: 0
},
infoLabel: {
type: String,
default: ''
}
})
defineEmits(['redirect'])
</script>
18 changes: 17 additions & 1 deletion packages/core/src/Elements/Sidebar/OcSidebar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import Sidebar from './OcSidebar.vue'
import SidebarSubmenu from './OcSidebarSubmenu.vue'
import AccountSetup from './OcAccountSetup.vue'
import SidebarHead from './OcSidebarHead.vue'
import SideBarMenu from './OcSidebarMenu.vue'
import SidebarSubMenuItem from './OcSidebarSubMenuItem.vue'
import SidebarFooter from './OcSidebarFooter.vue'
import SidebarFeatureBanners from './OcSidebarFeatureBanners.vue'
import AccountSetupProgress from './OcAccountSetupProgress.vue'

export { Sidebar, SidebarSubmenu, AccountSetup }
export {
Sidebar,
SidebarSubmenu,
AccountSetup,
SidebarHead,
SideBarMenu,
SidebarSubMenuItem,
SidebarFooter,
SidebarFeatureBanners,
AccountSetupProgress
}
12 changes: 10 additions & 2 deletions packages/core/src/Elements/Sidebar/OcSidebar.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Theme, Sidebar } from '@/orchidui-core'
import { Theme, Sidebar, SidebarFeatureBanners, AccountSetupProgress } from '@/orchidui-core'

import {
PAYMENTS_SIDEBAR_GROUP,
Expand Down Expand Up @@ -27,7 +27,7 @@ export const Default = {
progress: 80
},
render: (args) => ({
components: { Sidebar, Theme, OcAccountSetup },
components: { Sidebar, Theme, OcAccountSetup, SidebarFeatureBanners, AccountSetupProgress },
setup() {
return { args }
},
Expand All @@ -38,6 +38,14 @@ export const Default = {
:sidebar-menu="args.payment_sidebar_menu"
:isExpanded="args.isExpanded"
@changeExpanded="args.isExpanded = $event">
<template #banner>
<AccountSetupProgress :value="43" info-label="Add your bank account" />
<SidebarFeatureBanners
title="Late invoice fee"
is-stacked
description="You can now automate late fees on unpaid invoices by setting a fixed amount or percentage of the total, applied after a custom grace period."
/>
</template>
<template #before>
<OcAccountSetup :isExpanded="args.isExpanded" :progress="args.progress"/>
</template>
Expand Down
171 changes: 52 additions & 119 deletions packages/core/src/Elements/Sidebar/OcSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup>
import { ref, reactive, onMounted, computed } from 'vue'
import { Icon, SidebarSubmenu, Dropdown } from '@/orchidui-core'
import { reactive, onMounted, computed } from 'vue'
import { SidebarHead, SideBarMenu, SidebarSubMenuItem, SidebarFooter } from '@/orchidui-core'
const emit = defineEmits(['changeExpanded', 'click:sidebar-icon', 'changeExpandedMenus'])
const emit = defineEmits(['changeExpanded', 'click:sidebar-icon', 'changeExpandedMenus', 'redirect', 'user-click', 'support-click'])
const props = defineProps({
class: {
Expand All @@ -14,11 +14,12 @@ const props = defineProps({
},
sidebarMenu: {
type: Array
},
displayName: {
type: String
}
})
const dropdownOpen = ref([])
const state = reactive({
loading: true,
expanded: []
Expand All @@ -34,8 +35,16 @@ const expandMenu = (id) => {
emit('changeExpandedMenus', state.expanded)
}
const expandOrRedirect = (menuItem) => {
if (menuItem.children?.length) {
expandMenu(menuItem.name)
} else {
emit('redirect', menuItem.path)
}
}
const allClassName = computed(() => {
let classNames = props.isExpanded ? 'w-[300px] ' : 'w-[102px] '
let classNames = props.isExpanded ? 'w-[300px] ' : 'w-[76px] '
return classNames + props.class
})
Expand All @@ -61,127 +70,51 @@ onMounted(() => {
class="cursor-pointer max-h-[inherit] transition-all duration-300 ease-in-out relative bg-[var(--oc-sidebar-background)]"
:class="allClassName"
>
<div class="grid py-7 w-full max-h-[inherit] overflow-y-auto overflow-x-hidden gap-3 px-8">
<div class="grid py-4 max-h-[inherit] gap-3 px-6">
<slot name="before" :is-expanded="isExpanded" />
<template v-for="(sidebar, index) in sidebarMenu" :key="index">
<h2
v-if="isExpanded && sidebar.label"
class="text-sm uppercase text-[var(--oc-sidebar-menu-title)] my-3"
>
{{ sidebar.label }}
</h2>

<div
v-if="(!sidebar.label || !isExpanded) && index !== 0"
class="my-3"
:class="isExpanded ? 'px-0' : 'px-3'"
<div v-if="!isExpanded" class="border-t border-oc-gray-200 last:hidden first:hidden"></div>
<SidebarHead
v-if="sidebar.label || sidebar.items.length > 0"
:label="sidebar.label"
:is-sidebar-expanded="isExpanded"
>
<div class="w-full border-b border-[var(--oc-sidebar-menu-title)] opacity-50" />
</div>
<template v-for="(menu, menuIndex) in sidebar.items" :key="menuIndex">
<div class="flex flex-col">
<div
class="flex items-center rounded transition-all duration-500 hover:bg-[var(--oc-sidebar-menu-hover)]"
:class="{
'px-5 py-3': isExpanded,
'font-medium bg-[var(--oc-sidebar-menu-active)] text-[var(--oc-sidebar-menu-active-text)]':
menu.active
}"
@click="expandMenu(menu.name)"
>
<Icon
v-if="isExpanded"
width="22"
height="22"
class="z-[1] relative"
:class="{
'text-[var(--oc-sidebar-menu-active-icon)]': !menu.active,
'text-[var(--oc-sidebar-menu-active-icon-active)]': menu.active
}"
:name="menu.icon"
<SideBarMenu
v-for="(menu, menuIndex) in sidebar.items"
:key="menuIndex"
:icon="menu.icon"
:label="menu.label"
:is-active="menu.active"
:is-expanded="isExpanded"
:is-menu-expanded="state.expanded.includes(menu.name)"
@click="expandOrRedirect(menu)"
@close-menu="expandMenu(menu.name)"
>
<SidebarSubMenuItem
v-for="(submenu, submenuIndex) in menu.children"
:key="submenuIndex"
:icon="submenu.icon"
:label="submenu.label"
:is-active="submenu.active"
:is-expanded="isExpanded"
@click="$emit('redirect', submenu.path)"
/>

<Dropdown
v-else
v-model="dropdownOpen[menu.name + '-' + menuIndex]"
placement="right-start"
>
<button
type="button"
:class="{
'p-4': !isExpanded
}"
>
<Icon
width="22"
height="22"
:class="{
'text-[var(--oc-sidebar-menu-active-icon)]': !menu.active,
'text-[var(--oc-sidebar-menu-active-icon-active)]': menu.active
}"
:name="menu.icon"
@click="$emit('click:sidebar-icon', menu)"
/>
</button>
<template #menu>
<div
v-if="dropdownOpen[menu.name + '-' + menuIndex]"
class="p-3 gap-4 bg-oc-bg shadow-sm rounded w-[200px]"
>
<div
v-if="!menu.children"
class="flex items-center rounded hover:bg-[var(--oc-sidebar-menu-hover)]"
:class="{
'font-medium bg-[var(--oc-sidebar-menu-active)] text-[var(--oc-sidebar-menu-active-text)]':
menu.active
}"
>
<slot v-if="!isExpanded" name="label" :menu="menu" />
</div>
<SidebarSubmenu v-if="menu.children" :menu="menu" is-expanded>
<template #label="{ submenu }">
<slot name="submenu_label" :menu="menu" :submenu="submenu" />
</template>
</SidebarSubmenu>
</div>
</template>
</Dropdown>

<!-- <transition-->
<!-- tag="div"-->
<!-- class="transition-all duration-500"-->
<!-- leave-active-class="opacity-0"-->
<!-- enter-from-class="opacity-0"-->
<!-- enter-to-class="opacity-100"-->
<!-- >-->
<slot v-if="isExpanded" name="label" :menu="menu" />
<!-- </transition>-->
</div>
<div v-if="isExpanded" class="relative flex flex-col">
<div class="absolute border-l left-[27px] bottom-[17px] h-full" />
<SidebarSubmenu
v-if="menu.children"
:menu="menu"
:class="state.expanded.includes(menu.name) && 'mt-3'"
:is-expanded-sidebar="isExpanded"
:is-expanded="state.expanded.includes(menu.name)"
>
<template #label="{ submenu }">
<slot
name="submenu_label"
:menu="menu"
:submenu="submenu"
:is-expanded="isExpanded"
/>
</template>
</SidebarSubmenu>
</div>
</div>
</template>
</SideBarMenu>
</SidebarHead>
</template>
<slot name="after" :is-expanded="isExpanded" />
</div>
<SidebarFooter
:is-expanded="isExpanded"
:display-name="displayName"
@user-click="$emit('user-click')"
@support-click="$emit('support-click')"
>
<slot name="banner" />
</SidebarFooter>
</div>
</template>
37 changes: 37 additions & 0 deletions packages/core/src/Elements/Sidebar/OcSidebarFeatureBanners.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div class="relative">
<div class="border absolute top-2 left-0 w-full h-[calc(100%-4px)] border-oc-gray-200 rounded pt-2">
</div>
<div class="border relative z-10 bg-white border-oc-gray-200 shadow-normal rounded p-2 flex flex-col gap-y-2">
<div class="py-2 px-3 gap-x-3 flex items-center">
<Icon name="sparkle-2" class="text-oc-accent-2" />
<div class="text-oc-accent-2 flex-1 font-medium">
{{ title }}
</div>
<div class="flex items-center gap-x-2">
<Icon name="x" class="text-oc-text-300 hover:text-oc-text" width="14" height="14" @click="$emit('close')" />
<Icon name="arrow-top-right" class="text-oc-text-300 hover:text-oc-text" width="14" height="14" @click="$emit('redirect')" />
</div>
</div>
<div class="px-3 pb-3 text-oc-text-400 text-sm">{{ description }}</div>
</div>
</div>
</template>

<script setup>
import { Icon } from '@/orchidui-core'
defineProps({
isStacked: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
description: {
type: String,
default: ''
}
})
</script>
31 changes: 31 additions & 0 deletions packages/core/src/Elements/Sidebar/OcSidebarFooter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div
class="py-4 sticky bottom-0 left-0 px-6 bg-oc-gray-50 border-t border-oc-gray-200" >
<div class="flex flex-col gap-y-3">
<slot v-if="isExpanded"></slot>
<div
class="flex items-center gap-x-3"
:class="{
'flex-col gap-y-4': !isExpanded
}"
>
<div class="px-3 flex flex-1 items-center gap-x-3 text-oc-primary" @click="$emit('support-click')">
<Icon name="chat-2" width="18" height="18" />
<span v-if="isExpanded">Contact support</span>
</div>
<Avatar :size="32" class="shrink-0 uppercase" @click="$emit('user-click')">{{ displayName || 'J' }}</Avatar>
</div>
</div>
</div>
</template>

<script setup>
import { Avatar, Icon } from '@/orchidui-core'
defineProps({
displayName: String,
isExpanded: Boolean
})
defineEmits(['user-click', 'support-click'])
</script>
Loading

0 comments on commit 2f4db9f

Please sign in to comment.