-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Nav): the icon is not centered when the width of Nav in iconOnly …
…mode is less than the default width
- Loading branch information
泊淞
committed
Jan 21, 2025
1 parent
fcb7abd
commit 394eb78
Showing
10 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,3 +90,4 @@ src/core-temp | |
|
||
# tests snapshots diff | ||
components/**/__tests__/snapshots/__diff__/** | ||
cypress/screenshots/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.demo-ctl { | ||
background-color: #f1f1f1; | ||
border-left: 4px solid #0d599a; | ||
color: #0a7ac3; | ||
margin-bottom: 20px; | ||
padding: 5px; | ||
} | ||
.demo-ctl .next-radio-group { | ||
margin: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# zh-CN order=2 | ||
|
||
# 只显示图标-宽度自适应 | ||
|
||
Nav 可设置 iconOnly 属性,只显示图标,以减少占用空间。可以根据设定的iconOnlyWidth为100%,来让icon自适应居中展示,这种情况下需要Nav外部容器有具体宽度。 | ||
|
||
# en-US order=2 | ||
|
||
# Only show icon - width adaptive | ||
|
||
Nav could set the iconOnly property to reduce the footprint. You can set iconOnlyWidth to 100% to make the icon adapt and center itself. In this case, the external container of the Nav needs to have a specific width. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Nav, Radio } from '@alifd/next'; | ||
import type { NavProps } from '@alifd/next/types/nav'; | ||
|
||
type AppState = Pick< | ||
NavProps, | ||
'iconOnly' | 'hasTooltip' | 'hasArrow' | 'iconOnlyWidth' | 'iconTextOnly' | ||
> & { | ||
width?: number; | ||
}; | ||
|
||
const { Item, SubNav } = Nav; | ||
|
||
class App extends React.Component { | ||
state: AppState = { | ||
iconOnly: false, | ||
hasTooltip: true, | ||
hasArrow: true, | ||
iconOnlyWidth: '100%', | ||
iconTextOnly: false, | ||
width: 200, | ||
}; | ||
|
||
setValue(name: keyof AppState, value: string) { | ||
this.setState({ | ||
[name]: value === 'true', | ||
}); | ||
} | ||
|
||
iconfontChange(value: string) { | ||
const props: AppState = {}; | ||
props.iconOnly = value === 'true'; | ||
if (props.iconOnly) { | ||
props.width = 40; | ||
} else { | ||
props.width = 200; | ||
} | ||
this.setState(props); | ||
} | ||
|
||
render() { | ||
const { iconOnly, hasTooltip, hasArrow, iconTextOnly } = this.state; | ||
return ( | ||
<div> | ||
<div className="demo-ctl"> | ||
<Radio.Group | ||
shape="button" | ||
size="medium" | ||
value={iconOnly && iconTextOnly ? 'trueText' : iconOnly ? 'true' : 'false'} | ||
onChange={this.iconfontChange.bind(this)} | ||
> | ||
<Radio value="true">iconOnly=true</Radio> | ||
<Radio value="false">iconOnly=false</Radio> | ||
</Radio.Group> | ||
</div> | ||
<div style={{ width: this.state.width }}> | ||
<Nav | ||
iconOnlyWidth={this.state.iconOnlyWidth} | ||
iconOnly={iconOnly} | ||
iconTextOnly={iconTextOnly} | ||
hasArrow={hasArrow} | ||
hasTooltip={hasTooltip} | ||
hozInLine | ||
> | ||
<Item icon="account">三个字</Item> | ||
<Item icon="account">四个字的</Item> | ||
<Item icon="account">五个字导航</Item> | ||
<Item icon={'atm'}>六个字的导航</Item> | ||
<Item icon={<span>QAQ</span>}>七个字的长导航</Item> | ||
<SubNav icon="account" label="Sub Nav"> | ||
<Item icon="account">Item 1</Item> | ||
<Item icon="account">Item 2</Item> | ||
<Item icon="account">Item 3</Item> | ||
<Item icon="account">Item 4</Item> | ||
</SubNav> | ||
</Nav> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render(<App />, mountNode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters