Skip to content

Commit 4ef9ff7

Browse files
committed
feat: Add SplitViewCommand support controlled show label text
Close #17
1 parent 3df7d04 commit 4ef9ff7

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

docs/src/routes/Components/NavigationView/SimpleExample.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ export default class SimpleExample extends React.Component<React.HTMLAttributes<
7070
</NavigationView>
7171
</div>
7272

73+
<div>
74+
<NavigationView
75+
isControlled={false}
76+
style={{ width: 640, height: 640, ...baseStyle }}
77+
pageTitle="San Francisco"
78+
displayMode="compact"
79+
autoResize={false}
80+
initWidth={120}
81+
expandedWidth={480}
82+
defaultExpanded={false}
83+
navigationTopNodes={navigationTopNodes}
84+
navigationBottomNodes={navigationBottomNode}
85+
focusNavigationNodeIndex={2}
86+
>
87+
<img src={require("./components/images/golden-gate-bridge-2037990_1280.jpg")} height="100%" style={{ objectFit: "cover" }} />
88+
</NavigationView>
89+
</div>
7390
</div>
7491
);
7592
}

src/NavigationView/index.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,12 @@ export class NavigationView extends React.Component<NavigationViewProps, Navigat
181181

182182
getNewNodeProps = (currNode: any, index: number, expanded?: boolean, haveExpandedNode?: boolean) => {
183183
const { onClick } = currNode.props;
184+
const isSplitViewCommand = currNode && currNode.type === SplitViewCommand;
184185
const { focusNodeIndex } = this.state;
186+
185187
return {
186188
key: `${index} ${expanded}`,
189+
showLabel: isSplitViewCommand ? this.state.expanded : void 0,
187190
visited: focusNodeIndex === void 0 ? void 0 : focusNodeIndex === index,
188191
onClick: (e: any) => {
189192
this.setState({
@@ -297,17 +300,15 @@ export class NavigationView extends React.Component<NavigationViewProps, Navigat
297300
</div>
298301
</div>
299302
</div>
300-
{isCompact ? (
301-
<div
302-
style={{
303-
width: "100%",
304-
height: "100%",
305-
overflow: "hidden"
306-
}}
307-
>
308-
{children}
309-
</div>
310-
) : children}
303+
<div
304+
style={{
305+
width: "100%",
306+
height: "100%",
307+
overflow: "hidden"
308+
}}
309+
>
310+
{children}
311+
</div>
311312
</div>
312313
);
313314

src/SplitViewCommand/index.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ export interface DataProps {
2525
* Use 10ft Design mode.
2626
*/
2727
isTenFt?: boolean;
28+
/**
29+
* Set show label text.
30+
*/
31+
showLabel?: boolean;
2832
}
2933

3034
export interface SplitViewCommandProps extends DataProps, React.HTMLAttributes<HTMLDivElement> {}
3135

3236
export class SplitViewCommand extends React.Component<SplitViewCommandProps> {
3337
static defaultProps: SplitViewCommandProps = {
34-
isTenFt: false
38+
isTenFt: false,
39+
showLabel: true
3540
};
3641

3742
displayName: "SplitViewCommand";
@@ -50,6 +55,7 @@ export class SplitViewCommand extends React.Component<SplitViewCommandProps> {
5055
onMouseLeave,
5156
isTenFt,
5257
iconStyle,
58+
showLabel,
5359
...attributes
5460
} = this.props;
5561
const { theme } = this.context;
@@ -95,7 +101,16 @@ export class SplitViewCommand extends React.Component<SplitViewCommandProps> {
95101
}
96102

97103
function getStyles(splitViewCommand: SplitViewCommand) {
98-
const { context, props: { style, iconStyle, visited, isTenFt } } = splitViewCommand;
104+
const {
105+
context,
106+
props: {
107+
style,
108+
iconStyle,
109+
visited,
110+
isTenFt,
111+
showLabel
112+
}
113+
} = splitViewCommand;
99114
const { theme } = context;
100115
const { prefixStyle } = theme;
101116

@@ -135,7 +150,9 @@ function getStyles(splitViewCommand: SplitViewCommand) {
135150
}),
136151
label: {
137152
color: isTenFt ? void 0 : (visited ? theme.accent : theme.baseHigh),
138-
cursor: "default"
153+
cursor: "default",
154+
opacity: showLabel ? 1 : 0,
155+
transition: "opacity .25s"
139156
}
140157
};
141158
}

0 commit comments

Comments
 (0)