Skip to content

Commit

Permalink
[Home] fixes nav styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Sep 21, 2023
1 parent 4a6bb63 commit 94bff1d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ToolPage} from '#/main/core/tool/containers/page'

import {getTabTitle} from '#/plugin/home/tools/home/utils'
import {Tab as TabTypes} from '#/plugin/home/prop-types'
import {Tabs} from '#/plugin/home/tools/home/components/tabs'
import {HomeTabs} from '#/plugin/home/tools/home/components/tabs'

const HomePage = props =>
<ToolPage
Expand All @@ -21,10 +21,10 @@ const HomePage = props =>
}] : [], props.breadcrumb || [])}

header={1 < props.tabs.length ?
<Tabs
<HomeTabs
prefix={props.basePath+props.path}
tabs={props.tabs}
currentContext={props.currentContext}
currentTabId={get(props.currentTab, 'id')}
showSubMenu={props.showSubMenu}
showHidden={props.showHidden}
/> : undefined
Expand Down
144 changes: 77 additions & 67 deletions src/plugin/home/Resources/modules/tools/home/components/tabs.jsx
Original file line number Diff line number Diff line change
@@ -1,104 +1,114 @@
import React, {useEffect, useState} from 'react'
import React from 'react'
import {PropTypes as T} from 'prop-types'
import classes from 'classnames'
import {get, isEmpty} from 'lodash'
import tinycolor from 'tinycolor2'
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'

import {trans} from '#/main/app/intl'
import {Button} from '#/main/app/action/components/button'
import {CALLBACK_BUTTON} from '#/main/app/buttons'
import {MENU_BUTTON, LINK_BUTTON} from '#/main/app/buttons'
import {LinkButton} from '#/main/app/buttons/link/components/button'

import {Tab as TabTypes} from '#/plugin/home/prop-types'

const Tab = ({tab, prefix, closeTab, isChild = false}) =>
const Tab = ({tab, prefix}) =>
<LinkButton
key={tab.id}
className={classes('nav-tab', {
'nav-tab-hidden': get(tab, 'restrictions.hidden'),
'top-tab': !isChild,
'dropdown-tab': isChild
})}
className="home-nav-link nav-link"
target={`${prefix}/${tab.slug}`}
activeStyle={{
backgroundColor: get(tab, 'display.color'),
borderColor: get(tab, 'display.color')
}}
onClick={closeTab}
>
{tab.icon &&
<span className={classes('fa fa-fw', `fa-${tab.icon}`, tab.title && 'icon-with-text-right')} />
}
{tab.title}
</LinkButton>

const Tabs = props => {
const [expandedTab, setExpandedTab] = useState('')
useEffect(() => {
const previousWindowOnClick = window.onclick

window.onclick = ({target}) => !target.matches('top-tabs') && setExpandedTab('')

return () => {
window.onclick = previousWindowOnClick
}
}, [])

const toggleTab = tab => {
const newState = tab.id === expandedTab ? '' : tab.id
setExpandedTab(newState)
}
const isTabExpanded = tab => tab.id === expandedTab

const getSubtabs = (subtabs) =>
<ul className="dropdown-tabs">
{subtabs.filter(subTab => props.showHidden || !get(subTab, 'restrictions.hidden', false)).map(subtab =>
<li className="dropdown-tab-item" key={subtab.id}>
<Tab tab={subtab} prefix={props.prefix} isChild={true} closeTab={() => setExpandedTab('')} />
</li>
)}
</ul>

return <nav className="tool-nav">
<ul className="top-tabs">
const HomeTabs = props =>
<nav className="home-nav mt-3">
<ul className="nav gap-1">
{props.tabs
.filter(tab => props.showHidden || !get(tab, 'restrictions.hidden', false))
.map((tab) => {
const canShowSubTabs = !isEmpty(tab.children) && props.showSubMenu
const children = tab.children
.filter(subTab => props.showHidden || !get(subTab, 'restrictions.hidden', false))
const canShowSubTabs = !isEmpty(children) && props.showSubMenu

let color
if (get(tab, 'display.color')) {
color = tinycolor(get(tab, 'display.color'))
}

return (
<li
key={tab.id}
className={classes('home-nav-item nav-item', canShowSubTabs && 'btn-group', {
'home-nav-item-hidden': get(tab, 'restrictions.hidden')
}, props.currentTabId === tab.id && {
'active': props.currentTabId === tab.id,
'text-light': color && color.isDark(),
'text-dark': color && color.isLight()
})}
style={props.currentTabId === tab.id ? {
backgroundColor: get(tab, 'display.color'),
borderColor: get(tab, 'display.color')
} : undefined}
>
<Tab tab={tab} prefix={props.prefix} />
{canShowSubTabs &&
<Button
className="home-nav-expand"
type={MENU_BUTTON}
icon="fa fa-fw fa-caret-down"
label={trans('show_sub_tabs')}
tooltip="bottom"
menu={{
align: 'right',
items: children.map(subTab => {
let childColor
if (get(subTab, 'display.color')) {
childColor = tinycolor(get(subTab, 'display.color'))
}

return <li className={classes('top-tab-item', {'dropdown': canShowSubTabs})} key={tab.id}>
<div className="top-item">
<Tab tab={tab} prefix={props.prefix} closeTab={() => setExpandedTab('')} />
{canShowSubTabs && <Button
className="expand-sub-menu"
type={CALLBACK_BUTTON}
icon={classes('fa fa-fw', {
'fa-caret-up': isTabExpanded(tab),
'fa-caret-down': !isTabExpanded(tab)
})}
label=""
callback={() => toggleTab(tab)}
/>}
</div>
{canShowSubTabs && isTabExpanded(tab) && getSubtabs(tab.children)}
</li>
return {
type: LINK_BUTTON,
className: classes(props.currentTabId === subTab.id && {
'text-light': childColor && childColor.isDark(),
'text-dark': childColor && childColor.isLight()
}),
target: `${props.prefix}/${subTab.slug}`,
icon: subTab.icon ? `fa fa-fw fa-${subTab.icon}` : undefined,
label: subTab.title,
activeStyle: props.currentTabId === subTab.id && {
backgroundColor: get(subTab, 'display.color'),
borderColor: get(subTab, 'display.color')
}
}
})
}}
/>
}
</li>
)
})
}
</ul>
</nav>
}

Tabs.propTypes = {
showHidden: T.bool,
showSubMenu: T.bool,
HomeTabs.propTypes = {
prefix: T.string,
tabs: T.arrayOf(T.shape(
TabTypes.propTypes
))
)),
currentTabId: T.string,
showHidden: T.bool,
showSubMenu: T.bool
}

Tabs.defaultProps = {
HomeTabs.defaultProps = {
prefix: ''
}

export {
Tabs
HomeTabs
}
8 changes: 3 additions & 5 deletions src/plugin/home/Resources/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Claroline & bootstrap variables
@import "src/main/app/Resources/styles/variables";

$home-tab-color: $body-color;
$home-tab-bg: $gray-lighter;
$home-tab-border-radius: $border-radius-sm;
$home-tab-hover-color: $body-color;
$home-tab-hover-bg: white;
$home-tab-color: $body-color !default;
$home-tab-bg: var(--#{$prefix}tertiary-bg) !default;
$home-tab-border-radius: $nav-pills-border-radius !default;
90 changes: 13 additions & 77 deletions src/plugin/home/Resources/styles/tools/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,36 @@
@import "../variables";
@import "../components/widget";

.tool-nav {
.home-nav {
order: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
align-self: flex-start;
justify-content: flex-start;
align-items: center;

margin: 0 ($grid-gutter-width * .5);

.top-tabs {
display: flex;
padding-left: 0;
margin-bottom: 0;
list-style: none;
flex-wrap: wrap;
}

.top-tab-item.dropdown {
position: relative;

.top-tab {
margin-right: 0;
padding: $padding-large-vertical $padding-large-horizontal;
}
}

.dropdown-tabs {
position: absolute;
padding-left: math.div($padding-large-vertical, 2);
list-style: none;
z-index: 1;
}

.nav-tab-hidden {
color: var(--#{$prefix}secondary-color);
text-decoration: line-through !important;
}

.nav-tab {
position: relative;
.home-nav-item {
color: $home-tab-color;
padding: $padding-large-vertical $padding-large-horizontal;
margin: 5px;
background: $home-tab-bg;
border: 1px solid transparent;
border-radius: $home-tab-border-radius;

&:hover {
color: $home-tab-hover-color;
background: $home-tab-hover-bg;
}

&.active {
border-color: $primary; // can be overridden by tab config
background: $primary; // can be overridden by tab config

@include text-movie-subtitles();
@include box-shadow($box-shadow);
color: $nav-pills-link-active-color;
background: $nav-pills-link-active-bg;
}
}

.nav-tab {
display: block;
text-decoration: none;
white-space: nowrap;

&.dropdown-tab {
margin: 0;
border-radius: unset;
}
.home-nav-item-hidden {
color: var(--#{$prefix}secondary-color);
text-decoration: line-through !important;
}

.top-item {
display: flex;

.expand-sub-menu {
height: auto;
padding-left: 7px;

color: $home-tab-color;
background: $home-tab-bg;

border-left: 1px solid;
//margin: $padding-xs-horizontal 0;
.home-nav-expand {
padding: $nav-link-padding-y ($nav-link-padding-x*.5);
}

&:hover {
color: $home-tab-hover-color;
background: $home-tab-hover-bg;
@include box-shadow($box-shadow);
}
}
.home-nav-expand,
.home-nav-link {
color: inherit;
}
}

Expand Down

0 comments on commit 94bff1d

Please sign in to comment.