Skip to content

Commit 4fba4eb

Browse files
author
Mohsen Biglari
committed
alter propsManagers
1 parent 1a17f93 commit 4fba4eb

18 files changed

+218
-278
lines changed

src/com/react-dynamic-tabs/panel/panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Panel = memo(function Panel(props) {
66
React.useContext(ForceUpdateContext);
77
const { id, selectedTabID } = props
88
, api = useContext(ApiContext)
9-
, panelProps = panelPropsManager.get({ isSelected: id === selectedTabID, api, id });
9+
, panelProps = panelPropsManager({ isSelected: id === selectedTabID, api, id });
1010
return (
1111
<div {...panelProps}>
1212
{api.getTab(id).panelComponent}
Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
export default Object.create({
2-
get: function (param) {
3-
const { api } = param, { cssClasses, keyTemps } = api.getSetting();
4-
Object.assign(param, { cssClasses, keyTemps, op: api.getOptions() });
5-
return this._getA11Y(this._getSelected(this._getBase(param), param), param);
6-
},
7-
_getBase: function ({ id, cssClasses }) {
8-
return {
1+
export default function ({ isSelected, api, id }) {
2+
const op = api.optionsManager.options, setting = api.optionsManager.setting
3+
, result = {
94
'tab-id': id,
10-
className: cssClasses.panel,
5+
className: setting.panelClass,
116
};
12-
},
13-
_getSelected: function (obj, { isSelected, cssClasses }) {
14-
if (isSelected) {
15-
const { selected } = cssClasses;
16-
obj.className += ` ${selected}`;
17-
};
18-
return obj;
19-
},
20-
_getA11Y: function (obj, { op, isSelected, id, keyTemps }) {
21-
if (op.accessibility && (!op.isCustomTabComponent)) {
22-
obj.role = 'tabpanel';
23-
obj.id = keyTemps.panel(id);
24-
obj['aria-hidden'] = isSelected ? false : true;
25-
obj['aria-labelledby'] = keyTemps.ariaLabelledby(id);
26-
};
27-
return obj;
28-
}
29-
});
7+
// check if it is selected
8+
if (isSelected) {
9+
result.className += ` ${setting.selectedClass}`;
10+
};
11+
// check if accessibility is enable
12+
if (op.accessibility) {
13+
result.role = 'tabpanel';
14+
result.id = setting.panelIdTemplate(id);
15+
result['aria-hidden'] = isSelected ? false : true;
16+
result['aria-labelledby'] = setting.ariaLabelledbyIdTemplate(id);
17+
};
18+
return result;
19+
};

src/com/react-dynamic-tabs/panelList/panelList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ApiContext, StateContext } from '../utils/context.js';
55
const PanelList = memo(function PanelList(props) {
66
const { openTabIDs, selectedTabID } = React.useContext(StateContext)
77
, api = React.useContext(ApiContext)
8-
, { cssClasses, cssClasses: { panellist } } = api.getSetting()
9-
, className = panellist + ' ' + cssClasses[api.getOptions().direction];
8+
, setting = api.optionsManager.setting
9+
, className = setting.panellistClass + ' ' + setting[api.getOption('direction') + 'class'];
1010
return (
1111
<div className={className}>
1212
{openTabIDs.map(id =>

src/com/react-dynamic-tabs/tab/defaulTabInner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22
const DefaulTabInner = function (props) {
33
return (
4-
<button {...props.txtWidgetProps}>
4+
<button {...props.tabProps}>
55
{props.children}
66
{
7-
props.iconProps &&
7+
props.hasOwnProperty('iconProps') &&
88
<span {...props.iconProps}></span>
99
}
1010
</button>

src/com/react-dynamic-tabs/tab/tab.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import React, { memo } from "react";
22
import "./index.css";
33
import { ApiContext, ForceUpdateContext } from "../utils/context.js";
4-
import propsManager from './tabPropsManager';
4+
import TabPropsManager from './tabPropsManager.js';
55
const Tab = memo(
66
function Tab(props) {
77
React.useContext(ForceUpdateContext);
88
const { id, selectedTabID } = props
9-
, api = React.useContext(ApiContext), op = api.getOptions(), tabObj = api.getTab(id)
10-
, propsManagerParam = { api, id, isSelected: selectedTabID === id }
11-
, clkHandler = function (e) { api.eventHandlerFactory({ e, id }); }
12-
, TabInnerComponent = op.tabComponent;
9+
, api = React.useContext(ApiContext);
10+
const TabInnerComponent = api.getOption('tabComponent');
11+
if (!TabInnerComponent) {
12+
debugger;
13+
}
14+
const tabObj = api.getTab(id)
15+
, propsManager = new TabPropsManager({ api, id, isSelected: selectedTabID === id })
16+
, clkHandler = function (e) { api.eventHandlerFactory({ e, id }); };
1317
return (
14-
<li {...propsManager.getTabProps(propsManagerParam)} onClick={e => { clkHandler(e); }}>
15-
<TabInnerComponent {...propsManager.getTabInnerProps(propsManagerParam)}>
18+
<li {...propsManager.getTabProps()} onClick={e => { clkHandler(e); }}>
19+
<TabInnerComponent {...propsManager.getTabInnerProps()}>
1620
{tabObj.title}
1721
</TabInnerComponent>
1822
{
1923
tabObj.closable ?
20-
(<span {...propsManager.getTabCloseIconProps(propsManagerParam)} >&times;</span>) : null
24+
(<span {...propsManager.getCloseIconProps()} >&times;</span>) : null
2125
}
2226
</li>
2327
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const TabPropsManager = function ({ api, id, isSelected }) {
2+
this._api = api;
3+
this._id = id;
4+
this._isSelected = isSelected;
5+
this._op = api.optionsManager.options;
6+
this._setting = api.optionsManager.setting;
7+
this._tabObj = api.getTab(id);
8+
};
9+
TabPropsManager.prototype.getTabProps = function () {
10+
const outputProps = {
11+
'tab-id': this._id,
12+
className: this._setting.tabClass,
13+
tabIndex: -1
14+
};
15+
16+
//check if tab is selected
17+
if (this._isSelected) {
18+
outputProps.tabIndex = 0;
19+
outputProps.className += ` ${this._setting.selectedClass}`;
20+
}
21+
22+
// check if tab is disable
23+
if (this._tabObj.disable) {
24+
outputProps.tabIndex = -1;
25+
outputProps.className += ` ${this._setting.disableClass}`;
26+
}
27+
28+
// check if accessibility option is enable
29+
if (this._op.accessibility) {
30+
outputProps.role = 'tab';
31+
outputProps['aria-controls'] = this._setting.panelIdTemplate(this._id);
32+
outputProps['aria-labelledby'] = this._setting.ariaLabelledbyIdTemplate(this._id);
33+
outputProps['aria-selected'] = outputProps['aria-expanded'] = this._isSelected;
34+
}
35+
return outputProps;
36+
};
37+
TabPropsManager.prototype.getTabInnerProps = function () {
38+
const outputProps = {
39+
id: this._id,
40+
isSelected: this._isSelected,
41+
api: this._api.userProxy,
42+
tabProps: {
43+
'tab-id': this._id,
44+
className: this._setting.titleClass,
45+
tabIndex: -1
46+
}
47+
};
48+
// check if there is a iconClass option
49+
if (this._tabObj.iconClass) {
50+
outputProps.iconProps = {
51+
className: this._setting.iconClass + ' ' + this._tabObj.iconClass,
52+
role: 'presentation'
53+
};
54+
}
55+
56+
// check if accessibility option is enable
57+
if (this._op.accessibility) {
58+
outputProps.tabProps.id = this._setting.ariaLabelledbyIdTemplate(this._id);
59+
outputProps.tabProps.role = 'presentation';
60+
}
61+
return outputProps;
62+
};
63+
TabPropsManager.prototype.getCloseIconProps = function () {
64+
const outputProps = {
65+
className: this._setting.closeClass
66+
};
67+
// check if accessibility option is enable
68+
if (this._op.accessibility) {
69+
outputProps.role = 'presentation';
70+
}
71+
return outputProps;
72+
};
73+
export default TabPropsManager;

src/com/react-dynamic-tabs/tab/tabPropsManager/defaultTabInnerProps.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/com/react-dynamic-tabs/tab/tabPropsManager/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/com/react-dynamic-tabs/tab/tabPropsManager/tabProps.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/com/react-dynamic-tabs/tab/tabPropsManager/tabPropsManager.factory.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/com/react-dynamic-tabs/tab/tabPropsManager/tabcloseIconProps.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/com/react-dynamic-tabs/tab/tabPropsManager/userTabInnerProps.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/com/react-dynamic-tabs/tabList/tabList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import tablistPropsManager from './tablistPropsManager.js';
66
const TabList = memo(function TabList(props) {
77
const { openTabIDs, selectedTabID } = React.useContext(StateContext)
88
, api = React.useContext(ApiContext)
9-
, tablistProps = tablistPropsManager.get({ api });
9+
, tablistProps = tablistPropsManager({ api });
1010
return (
1111
<ul {...tablistProps}>
1212
{openTabIDs.map(id => <Tab key={id} id={id} selectedTabID={selectedTabID}></Tab>)}
Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
export default Object.create({
2-
get: function (param) {
3-
const { api } = param, { cssClasses } = api.getSetting();
4-
Object.assign(param, { cssClasses, op: api.getOptions() });
5-
return this._getA11Y(this._getBase(param), param);
6-
},
7-
_getBase: function ({ cssClasses, op }) {
8-
return { className: cssClasses.tablist + ' ' + cssClasses[op.direction] };
9-
},
10-
_getA11Y: function (obj, { op }) {
11-
if (op.accessibility && (!op.isCustomTabComponent))
12-
obj.role = 'tablist';
13-
return obj;
1+
export default function ({ api }) {
2+
const _setting = api.optionsManager.setting
3+
, _op = api.optionsManager.options
4+
, result = {
5+
className: _setting.tablistClass + ' ' + _setting[_op.direction + 'class']
6+
};
7+
if (_op.accessibility) {
8+
result.role = 'tablist';
149
}
15-
});
10+
return result;
11+
};
12+
// Object.create({
13+
// get: function ({ api }) {
14+
// this._setting = api.optionsManager. ;
15+
// this._op = api.optionsManager.options;
16+
// return this._getA11Y(this._getBase());
17+
// },
18+
// _getBase: function () {
19+
// return {
20+
// className: this._setting.tablistClass + ' ' +
21+
// this._setting[this._op.direction + 'class']
22+
// };
23+
// },
24+
// _getA11Y: function (obj) {
25+
// if (this._op.accessibility)
26+
// obj.role = 'tablist';
27+
// return obj;
28+
// }
29+
// });

0 commit comments

Comments
 (0)