Skip to content

Commit

Permalink
feat(component.tabs): Add new component tabs (#13)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boungnaseng <alex.boungnaseng.ext@corp.ovh.com>
Co-authored-by: schevreu <stevering@bkm.me>
  • Loading branch information
aboungnaseng-ovhcloud and stevering authored Apr 20, 2023
1 parent 66925d3 commit e73b220
Show file tree
Hide file tree
Showing 576 changed files with 3,311 additions and 4,208 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"registry": ""
},
"resolutions": {
"ua-parser-js": "0.7.18"
"ua-parser-js": "0.7.18",
"@types/react": "^16.14.0"
}
}
78 changes: 78 additions & 0 deletions packages/design/components/tabs/design-tabs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Preview

<osds-tabs style={{ pointerEvents: 'none' }}>
<osds-tab-bar slot="top">
<osds-tab-bar-item panel="one">One</osds-tab-bar-item>
<osds-tab-bar-item panel="two">Two</osds-tab-bar-item>
<osds-tab-bar-item panel="three">Three</osds-tab-bar-item>
</osds-tab-bar>
<osds-tab-panel name="one">Oles ipsum dolor sit amet, discere vero causae sed tempus</osds-tab-panel>
<osds-tab-panel name="two">Oles ipsum dolor sit amet, sql dicat aperiri port performance</osds-tab-panel>
<osds-tab-panel name="three">Oles ipsum dolor sit amet, habitasse ei neque pericula perpetua</osds-tab-panel>
</osds-tabs>

## Description

Tabs are an easy way to organize content by grouping similar information on the same page.
This allows content to be viewed without having to navigate away from that page.
They can also tend to be used to filter content via some common denominator.

## Zoning

The component is organized with a main content and a tab bar:

<osds-tabs style={{ pointerEvents: 'none' }}>
<osds-tab-bar slot="top">
Bar
</osds-tab-bar>
Content
</osds-tabs>

You have to place some items inside the tab bar:

<osds-tabs style={{ pointerEvents: 'none' }}>
<osds-tab-bar slot="top">
<osds-tab-bar-item panel="one">Item One</osds-tab-bar-item>
<osds-tab-bar-item panel="two">Item Two</osds-tab-bar-item>
<osds-tab-bar-item panel="three">Item Three</osds-tab-bar-item>
</osds-tab-bar>
Content
</osds-tabs>

Then your content represents your panel contents.

<osds-tabs style={{ pointerEvents: 'none' }}>
<osds-tab-bar slot="top">
<osds-tab-bar-item panel="one">Item One</osds-tab-bar-item>
<osds-tab-bar-item panel="two">Item Two</osds-tab-bar-item>
<osds-tab-bar-item panel="three">Item Three</osds-tab-bar-item>
</osds-tab-bar>
<osds-tab-panel name="one">Panel content one</osds-tab-panel>
</osds-tabs>

Tabs are often used in the top part of a web page, as it can act as a navigation focus.
They are left-centered by default.

## Sizes

There is only one size for now: `md`.

## Contrasted

For dark backgrounds, tabs have a contrasted version to be displayed.
When the `tabs` changed to contrasted, it changes all items to a `contrasted` mode.

## Disabled

You can disable some items :

<osds-tabs style={{ pointerEvents: 'none' }}>
<osds-tab-bar slot="top">
<osds-tab-bar-item panel="one">One</osds-tab-bar-item>
<osds-tab-bar-item panel="two" disabled>Two (disabled)</osds-tab-bar-item>
<osds-tab-bar-item panel="three">Three</osds-tab-bar-item>
</osds-tab-bar>
<osds-tab-panel name="one">Oles ipsum dolor sit amet, discere vero causae sed tempus</osds-tab-panel>
<osds-tab-panel name="two">Oles ipsum dolor sit amet, sql dicat aperiri port performance</osds-tab-panel>
<osds-tab-panel name="three">Oles ipsum dolor sit amet, habitasse ei neque pericula perpetua</osds-tab-panel>
</osds-tabs>
4 changes: 2 additions & 2 deletions packages/libraries/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"watch": "tsc -w -p tsconfig.esm.json",
"doc": "typedoc --plugin none src/* && typedoc --plugin typedoc-plugin-markdown --hideBreadcrumbs true --hideInPageTOC true && typedoc --json ./typedoc/typedoc.json --pretty && tsc src/utils/typedoc/typedoc-json-to-md.ts && node scripts/generate-typedoc-md.js",
"generate:licence": "npx generate-license-file --input package.json --output THIRD-PARTY-LICENCES --overwrite",
"test:spec": "jest",
"test:spec:ci": "jest --ci --detectOpenHandles"
"test:spec": "jest --coverage",
"test:spec:ci": "jest --ci --coverage --detectOpenHandles"
},
"peerDependencies": {
"@ovhcloud/ods-theming": ">=2"
Expand Down
4 changes: 4 additions & 0 deletions packages/libraries/core/scripts/generate-typedoc-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const components = [
'OdsRange',
'OdsSelect',
'OdsSkeleton',
'OdsTabs',
'OdsTabBar',
'OdsTabBarItem',
'OdsTabPanel',
'OdsText',
'OdsTextarea',
'OdsTile',
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/core/src/components/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export * from './radio-group/public-api';
export * from './radio-button/public-api';
export * from './range/public-api';
export * from './skeleton/public-api';
export * from './tabs/public-api';
export * from './select/public-api';

export * from './text/public-api';
export * from './textarea/public-api';
export * from './tile/public-api';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type OdsPanelValue = string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { OdsComponentAttributes } from '../../ods-component-attributes';

export interface OdsTabBarItemAttributes extends OdsComponentAttributes {
/**
* is this tab item is selected or not
*/
active: boolean;
/**
* is in contrasted mode or not
*/
contrasted: boolean;
/**
* The tab is disabled or not
*/
disabled: boolean;
/**
* The panel of the corresponding Tab
*/
panel: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export interface OdsTabBarItemBehavior {
/**
* reference to the host element.
*/
el: HTMLElement;

/**
* select item in order to make the corresponding panel displayed after
*/
select(): void;

/**
* will find the contrasted attribute of the tabs (parent main component)
* and set here the contrast automatically
*/
beforeInit(): void;

/** get the tab index of the item */
getTabIndex(): number | string;

/**
* handle the click on item.
* it will trigger the selection by calling select
*/
handleClick(): void;

/**
* handle the keyboard selection
* @param event - keyboard event
*/
handlePanelKeyEvent(event: KeyboardEvent): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { OdsComponentController } from '../../ods-component-controller';
import { OdsTabBarItem } from './ods-tab-bar-item';

/**
* common controller logic for text component used by the different implementations.
* it contains all the glue between framework implementation and the third party service.
*/
export class OdsTabBarItemController extends OdsComponentController<OdsTabBarItem> {
constructor(component: OdsTabBarItem) {
super(component);
}

/**
*
* @param event
*/
handlePanelKeyEvent(event: KeyboardEvent) {
if (!this.component.disabled) {
if (event.keyCode === 13 || event.keyCode === 32) {
this.component.select();
//event.defaultPrevented();
event.preventDefault();
}
}
}

getTabIndex(currentTabindex: number | string) {
if(this.component.disabled) {
return -1;
}

if (currentTabindex) {
return currentTabindex;
}

return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { OdsTabBarItemAttributes } from './ods-tab-bar-item-attributes';

/**
* Default attribute values of OdsTabs panel component
* (these are values for `OdsTabBarDefaultAttributes`)
*/
export const OdsTabBarItemDefaultAttributesDoc = {
panel: '',
active: false,
disabled: false,
contrasted: false
} as const;

export const odsTabBarItemDefaultAttributes = OdsTabBarItemDefaultAttributesDoc as OdsTabBarItemAttributes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { OdsComponentEvents } from '../../ods-component-events';
import { OdsTabItemSelectEventDetail } from '../ods-tab-item-select-event-detail';

export interface OdsTabBarItemEvents extends OdsComponentEvents {
odsTabItemSelectEvent: OdsTabItemSelectEventDetail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { OdsComponentMethods } from '../../ods-component-methods';

export interface OdsTabBarItemMethods extends OdsComponentMethods {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { OdsComponentGenericMethods } from '../../ods-component-generic-methods';
import { OdsComponentGenericEvents } from '../../ods-component-generic-events';
import { OdsComponent } from '../../ods-component';
import { OdsTabBarItemMethods } from './ods-tab-bar-item-methods';
import { OdsTabBarItemEvents } from './ods-tab-bar-item-events';
import { OdsTabBarItemController } from './ods-tab-bar-item-controller';
import { OdsTabBarItemAttributes } from './ods-tab-bar-item-attributes';
import { OdsTabBarItemBehavior } from './ods-tab-bar-item-behavior';

/**
* interface description ofe all implementation of `ods-tab-bar-item`.
* each implementation must have defined events, methods, attributes
* and one controller for the common behavior logic
*/
export type OdsTabBarItem<ComponentMethods extends OdsComponentGenericMethods<OdsTabBarItemMethods> = OdsComponentGenericMethods<OdsTabBarItemMethods>,
ComponentEvents extends OdsComponentGenericEvents<OdsTabBarItemEvents> = OdsComponentGenericEvents<OdsTabBarItemEvents>> =
OdsComponent<ComponentMethods, ComponentEvents, OdsTabBarItemAttributes, OdsTabBarItemController, OdsTabBarItemBehavior>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './ods-tab-bar-item'
export * from './ods-tab-bar-item-attributes';
export * from './ods-tab-bar-item-behavior';
export * from './ods-tab-bar-item-controller';
export * from './ods-tab-bar-item-default-attributes';
export * from './ods-tab-bar-item-events';
export * from './ods-tab-bar-item-methods';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { OdsComponentAttributes } from '../../ods-component-attributes';
import { OdsTabsSize, } from '../ods-tabs/ods-tabs-size';

export interface OdsTabBarAttributes extends OdsComponentAttributes {
size?: OdsTabsSize
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface OdsTabBarBehavior {
/**
* reference to the host element.
*/
el: HTMLElement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OdsComponentController } from '../../ods-component-controller';
import { OdsTabBar } from './ods-tab-bar';

/**
* common controller logic for text component used by the different implementations.
* it contains all the glue between framework implementation and the third party service.
*/
export class OdsTabBarController extends OdsComponentController<OdsTabBar> {
constructor(component: OdsTabBar) {
super(component);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OdsTabBarAttributes } from './ods-tab-bar-attributes';
import { OdsTabsSize, } from '../ods-tabs/ods-tabs-size';

/**
* Default attribute values of OdsTabs panel component
* (these are values for `OdsTabBarDefaultAttributes`)
* @enum
*/
export const OdsTabBarDefaultAttributesDoc = {
size: OdsTabsSize.md,
} as const;

export const odsTabBarDefaultAttributes = OdsTabBarDefaultAttributesDoc as OdsTabBarAttributes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { OdsComponentEvents } from '../../ods-component-events';

export interface OdsTabBarEvents extends OdsComponentEvents {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { OdsComponentMethods } from '../../ods-component-methods';

export interface OdsTabBarMethods extends OdsComponentMethods {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { OdsComponentGenericMethods } from '../../ods-component-generic-methods';
import { OdsComponentGenericEvents } from '../../ods-component-generic-events';
import { OdsComponent } from '../../ods-component';
import { OdsTabBarMethods } from './ods-tab-bar-methods';
import { OdsTabBarEvents } from './ods-tab-bar-events';
import { OdsTabBarController } from './ods-tab-bar-controller';
import { OdsTabBarAttributes } from './ods-tab-bar-attributes';
import { OdsTabBarBehavior } from './ods-tab-bar-behavior';

/**
* interface description ofe all implementation of `ods-tabs`.
* each implementation must have defined events, methods, attributes
* and one controller for the common behavior logic
*/
export type OdsTabBar<ComponentMethods extends OdsComponentGenericMethods<OdsTabBarMethods> = OdsComponentGenericMethods<OdsTabBarMethods>,
ComponentEvents extends OdsComponentGenericEvents<OdsTabBarEvents> = OdsComponentGenericEvents<OdsTabBarEvents>> =
OdsComponent<ComponentMethods, ComponentEvents, OdsTabBarAttributes, OdsTabBarController, OdsTabBarBehavior>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './ods-tab-bar'
export * from './ods-tab-bar-attributes';
export * from './ods-tab-bar-behavior';
export * from './ods-tab-bar-controller';
export * from './ods-tab-bar-default-attributes';
export * from './ods-tab-bar-events';
export * from './ods-tab-bar-methods';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { OdsPanelValue } from './ods-panel-value';
import { OdsTabBarItem } from './ods-tab-bar-item/ods-tab-bar-item';

export interface OdsTabItemSelectEventDetail {
panel: OdsPanelValue,
tabItem: OdsTabBarItem
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OdsComponentAttributes } from '../../ods-component-attributes';

export interface OdsTabPanelAttributes extends OdsComponentAttributes {
/**
* is the panel is active or nor
*/
active: boolean;
/**
* identifier name of the panel
*/
name: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface OdsTabPanelBehavior {
/**
* reference to the host element.
*/
el: HTMLElement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OdsComponentController } from '../../ods-component-controller';
import { OdsTabPanel } from './ods-tab-panel';

/**
* common controller logic for text component used by the different implementations.
* it contains all the glue between framework implementation and the third party service.
*/
export class OdsTabPanelController extends OdsComponentController<OdsTabPanel> {
constructor(component: OdsTabPanel) {
super(component);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OdsTabPanelAttributes } from './ods-tab-panel-attributes';

/**
* Default attribute values of OdsTabs panel component
* (these are values for `odsTabPanelDefaultAttributes`)
*/
export const odsTabPanelDefaultAttributesDoc = {
name: '',
active: false,
} as const;

export const odsTabPanelDefaultAttributes = odsTabPanelDefaultAttributesDoc as OdsTabPanelAttributes;
Loading

0 comments on commit e73b220

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy