Skip to content

Commit 7658d8d

Browse files
Make Global Nav region a class component
1 parent 629c5e3 commit 7658d8d

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

components/global-navigation-bar/region.jsx

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,52 +70,53 @@ const renderTertiary = (dividerClass, className, children) =>
7070
/**
7171
* Regions make up a GlobalNavigation Bar and typically contain links and dropdowns. The Primary region contains the AppSwitcher, Application Name, and Object Switcher. The secondary region typically has navigation betweens sections of the application. The tertiary region is aligned to the right side of the screen and contains shortcuts or actions.
7272
*/
73-
const Region = (props) => {
74-
let region;
75-
const dividerClass = props.dividerPosition ? `slds-context-bar__item--divider-${props.dividerPosition}` : null;
76-
77-
switch (props.region) {
78-
case 'primary':
79-
region = renderPrimary(dividerClass, props.className, props.children);
80-
break;
81-
case 'secondary':
82-
region = renderSecondary(dividerClass, props.className, props.children, props.navigation);
83-
break;
84-
case 'tertiary':
85-
region = renderTertiary(dividerClass, props.className, props.children);
86-
break;
87-
default:
88-
// do nothing
73+
const Region = React.createClass({
74+
displayName: GLOBAL_NAVIGATION_BAR_REGION,
75+
76+
propTypes: {
77+
/**
78+
* Contents of region. Expects `GlobalNavigationBarLink`, `GlobalNavigationBarDropdown`, `GlobalNavigationBarApplicationName`, `AppSwitcher`, but could be any component. This is the place to pass in an Object Switcher until that is supported.
79+
*/
80+
children: PropTypes.node,
81+
/**
82+
* Determines position of separating bar.
83+
*/
84+
dividerPosition: PropTypes.oneOf(['left', 'right']),
85+
/**
86+
* CSS classes to be added to the region
87+
*/
88+
className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
89+
/**
90+
* Wraps the `secondary` region in a `nav` and adds a role attribute
91+
*/
92+
navigation: PropTypes.bool,
93+
/**
94+
* Region wrap children in styling specific to that region.
95+
*/
96+
region: PropTypes.oneOf(['primary', 'secondary', 'tertiary']).isRequired
97+
},
98+
99+
render () {
100+
let region;
101+
const dividerClass = this.props.dividerPosition ? `slds-context-bar__item--divider-${this.props.dividerPosition}` : null;
102+
103+
switch (this.props.region) {
104+
case 'primary':
105+
region = renderPrimary(dividerClass, this.props.className, this.props.children);
106+
break;
107+
case 'secondary':
108+
region = renderSecondary(dividerClass, this.props.className, this.props.children, this.props.navigation);
109+
break;
110+
case 'tertiary':
111+
region = renderTertiary(dividerClass, this.props.className, this.props.children);
112+
break;
113+
default:
114+
// do nothing
115+
}
116+
117+
return region;
89118
}
90-
91-
return region;
92-
};
93-
94-
Region.displayName = GLOBAL_NAVIGATION_BAR_REGION;
95-
96-
Region.propTypes = {
97-
/**
98-
* Contents of region. Expects `GlobalNavigationBarLink`, `GlobalNavigationBarDropdown`, `GlobalNavigationBarApplicationName`, `AppSwitcher`, but could be any component. This is the place to pass in an Object Switcher until that is supported.
99-
*/
100-
children: PropTypes.node,
101-
/**
102-
* Determines position of separating bar.
103-
*/
104-
dividerPosition: PropTypes.oneOf(['left', 'right']),
105-
/**
106-
* CSS classes to be added to the region
107-
*/
108-
className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
109-
/**
110-
* Wraps the `secondary` region in a `nav` and adds a role attribute
111-
*/
112-
navigation: PropTypes.bool,
113-
/**
114-
* Region wrap children in styling specific to that region.
115-
*/
116-
region: PropTypes.oneOf(['primary', 'secondary', 'tertiary']).isRequired
117-
};
118-
119+
});
119120

120121
module.exports = Region;
121122
module.exports.regions = regions;

0 commit comments

Comments
 (0)