Skip to content

Commit 72e02ac

Browse files
(SalesPath): update classnames
1 parent 7b1ef61 commit 72e02ac

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/scripts/SalesPath.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ type SalesPathKey = string | number;
2323
*/
2424
const SalesPathTypeContext = createContext<SalesPathItemType>('incomplete');
2525

26-
const SalesPathHandlersContext = createContext<{
26+
const SalesPathContext = createContext<{
2727
onSelect?: Bivariant<(eventKey: SalesPathKey) => void>;
28+
activeKey?: SalesPathKey | null;
2829
}>({});
2930

3031
/**
@@ -44,7 +45,7 @@ export type SalesPathItemProps = {
4445
export const SalesPathItem: FC<SalesPathItemProps> = (props) => {
4546
const { className, eventKey, type: type_, title, completedTitle } = props;
4647
const evaluatedType = useContext(SalesPathTypeContext);
47-
const { onSelect } = useContext(SalesPathHandlersContext);
48+
const { onSelect, activeKey } = useContext(SalesPathContext);
4849
const type = type_ ?? evaluatedType;
4950

5051
const onItemClick = useEventCallback(() => {
@@ -53,9 +54,18 @@ export const SalesPathItem: FC<SalesPathItemProps> = (props) => {
5354
}
5455
});
5556

57+
const isSelected = activeKey === eventKey;
58+
const isCurrent = type === 'current';
59+
const isActive = isSelected || (isCurrent && activeKey == null);
60+
5661
const pathItemClassName = classnames(
57-
'slds-tabs_path__item',
58-
type ? `slds-is-${type}` : undefined,
62+
'slds-path__item',
63+
{
64+
'slds-is-complete': type === 'complete',
65+
'slds-is-current': isCurrent,
66+
'slds-is-incomplete': type === 'incomplete',
67+
'slds-is-active': isActive,
68+
},
5969
className
6070
);
6171

@@ -65,20 +75,20 @@ export const SalesPathItem: FC<SalesPathItemProps> = (props) => {
6575
return (
6676
<li className={pathItemClassName} role='presentation'>
6777
<a
68-
className='slds-tabs_path__link'
78+
className='slds-path__link'
6979
aria-selected='false'
7080
tabIndex={tabIndex}
7181
role='tab'
7282
aria-live='assertive'
7383
onClick={onItemClick}
7484
>
75-
<span className='slds-tabs_path__stage'>
85+
<span className='slds-path__stage'>
7686
<Icon category='utility' icon='check' size='x-small' />
7787
{type === 'complete' ? (
7888
<span className='slds-assistive-text'>{completedText}</span>
7989
) : null}
8090
</span>
81-
<span className='slds-tabs_path__title'>{title}</span>
91+
<span className='slds-path__title'>{title}</span>
8292
</a>
8393
</li>
8494
);
@@ -114,7 +124,7 @@ export const SalesPath = createFC<
114124
activeKey_,
115125
defaultActiveKey ?? null
116126
);
117-
const salesPathClassNames = classnames(className, 'slds-tabs_path');
127+
const salesPathClassNames = classnames(className, 'slds-path');
118128

119129
const onSelect = useEventCallback((itemKey: SalesPathKey) => {
120130
onSelect_?.(itemKey);
@@ -133,12 +143,12 @@ export const SalesPath = createFC<
133143
}
134144
});
135145

136-
const handlers = useMemo(() => ({ onSelect }), [onSelect]);
146+
const ctx = useMemo(() => ({ onSelect, activeKey }), [onSelect, activeKey]);
137147

138148
return (
139149
<div className={salesPathClassNames} role='application tablist'>
140-
<ul className='slds-tabs_path__nav' role='presentation'>
141-
<SalesPathHandlersContext.Provider value={handlers}>
150+
<ul className='slds-path__nav' role='presentation'>
151+
<SalesPathContext.Provider value={ctx}>
142152
{React.Children.map(children, (child, idx) => {
143153
const evaluatedType =
144154
idx === activeIdx
@@ -152,7 +162,7 @@ export const SalesPath = createFC<
152162
</SalesPathTypeContext.Provider>
153163
);
154164
})}
155-
</SalesPathHandlersContext.Provider>
165+
</SalesPathContext.Provider>
156166
</ul>
157167
</div>
158168
);

0 commit comments

Comments
 (0)