diff --git a/components/shell/__docs__/adaptor/index.tsx b/components/shell/__docs__/adaptor/index.tsx index 010a43c161..ae06bac171 100644 --- a/components/shell/__docs__/adaptor/index.tsx +++ b/components/shell/__docs__/adaptor/index.tsx @@ -1,11 +1,24 @@ import React from 'react'; import { Types } from '@alifd/adaptor-helper'; -import { Shell, Icon } from '@alifd/next'; +import { Shell, Icon, Nav, Search } from '@alifd/next'; + +interface AdaptorProps { + level: 'light' | 'dark' | 'brand'; + device: 'desktop' | 'tablet' | 'phone'; + branding?: boolean; + actions: boolean; + localNav: boolean; + appbar: boolean; + footer: boolean; + tooldock: boolean; + ancillary: boolean; + navigation: 'ver' | 'hoz'; +} export default { name: 'Shell', shape: ['normal'], - editor: shape => { + editor: (shape: string) => { return { props: [ { @@ -86,8 +99,7 @@ export default { tooldock, ancillary, navigation, - ...others - }) => { + }: AdaptorProps) => { let logoStyle = {}, shellStyle = {}; @@ -188,12 +200,12 @@ export default { ) : null} - {appbar ? : null} + {appbar ? : null}
- {ancillary ? : null} + {ancillary ? : null} {tooldock ? ( diff --git a/components/shell/__docs__/demo/basic/index.tsx b/components/shell/__docs__/demo/basic/index.tsx index 2f74855537..58f01c623f 100644 --- a/components/shell/__docs__/demo/basic/index.tsx +++ b/components/shell/__docs__/demo/basic/index.tsx @@ -1,8 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Search, Icon, Nav, Shell } from '@alifd/next'; - -const { SubNav, Item, Group, Divider } = Nav; +import { Search, Icon, Shell } from '@alifd/next'; class App extends React.Component { render() { diff --git a/components/shell/__docs__/demo/complicated/index.tsx b/components/shell/__docs__/demo/complicated/index.tsx index cbae2840df..480f4f94d5 100644 --- a/components/shell/__docs__/demo/complicated/index.tsx +++ b/components/shell/__docs__/demo/complicated/index.tsx @@ -2,13 +2,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Search, Icon, Nav, Shell, Radio } from '@alifd/next'; -const { SubNav, Item, Group, Divider } = Nav; +const { Item } = Nav; +type deviceType = 'tablet' | 'desktop' | 'phone'; class App extends React.Component { - state = { + state: { device: deviceType; navcollapse: boolean } = { device: 'desktop', + navcollapse: false, }; - onChange = device => { + onChange = (device: deviceType) => { this.setState({ device, }); @@ -20,8 +22,8 @@ class App extends React.Component { }); }; - onCollapseChange = (visible, e) => { - console.log('onCollapseChange:', visible, e); + onCollapseChange = (visible: boolean) => { + console.log('onCollapseChange:', visible); this.setState({ navcollapse: visible, @@ -124,7 +126,7 @@ class App extends React.Component { @ 2019 Alibaba Piecework 版权所有 - + diff --git a/components/shell/__docs__/demo/header-global-local/index.tsx b/components/shell/__docs__/demo/header-global-local/index.tsx index 09d3e3bb2e..de52c7c7b1 100644 --- a/components/shell/__docs__/demo/header-global-local/index.tsx +++ b/components/shell/__docs__/demo/header-global-local/index.tsx @@ -1,14 +1,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Menu, Search, Nav, Shell, Radio } from '@alifd/next'; +import { Search, Nav, Shell, Radio } from '@alifd/next'; -const { SubNav, Item, Group, Divider } = Nav; +const { Item } = Nav; +type deviceType = 'tablet' | 'desktop' | 'phone'; class App extends React.Component { - state = { + state: { device: deviceType } = { device: 'desktop', }; - onChange = device => { + onChange = (device: deviceType) => { this.setState({ device, }); diff --git a/components/shell/__docs__/demo/header-global/index.tsx b/components/shell/__docs__/demo/header-global/index.tsx index 020f4baa94..ffdfcbafb0 100644 --- a/components/shell/__docs__/demo/header-global/index.tsx +++ b/components/shell/__docs__/demo/header-global/index.tsx @@ -1,14 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Menu, Search, Nav, Shell, Radio } from '@alifd/next'; +import { Search, Nav, Shell, Radio } from '@alifd/next'; -const { SubNav, Item, Group, Divider } = Nav; +type deviceType = 'tablet' | 'desktop' | 'phone'; class App extends React.Component { - state = { + state: { device: deviceType } = { device: 'desktop', }; - onChange = device => { + onChange = (device: deviceType) => { this.setState({ device, }); diff --git a/components/shell/__docs__/index.en-us.md b/components/shell/__docs__/index.en-us.md index 21ed5d84cf..c750958263 100644 --- a/components/shell/__docs__/index.en-us.md +++ b/components/shell/__docs__/index.en-us.md @@ -15,13 +15,13 @@ Shell is the infrastructure framework of the whole application. It embodies the ### 何时使用 -- Shell should be configured according to the actual business requirements. -- The same application uses a unified Shell framework to avoid confusion. +- Shell should be configured according to the actual business requirements. +- The same application uses a unified Shell framework to avoid confusion. -````jsx +```jsx - + @@ -36,47 +36,49 @@ Shell is the infrastructure framework of the whole application. It embodies the -```` +``` `` uses css-grid, others are `display: flex` ## API ### Shell -| Param | Description | Type | Default Value | -| -------------------- | ------------ | ----------------- | ------------------ | -| device | Preset screen width, tt determines whether `Navigation` `LocalNavigation` `Ancillary`take space or not

**option**:
'phone', 'tablet', 'desktop' | Enum | desktop | -| type | type of Shell

**可选值**:
'light', 'dark', 'brand' | Enum | light | -| fixedHeader | fixed header or not. Doesn't work under IE11 | Boolean | false | +| Param | Description | Type | Default Value | Required | +| ----------- | ------------------------------------------------------------------------------------------------ | -------------------------------- | ------------- | -------- | +| device | Preset screen width, tt determines whether Navigation LocalNavigation Ancillarytake space or not | 'tablet' \| 'desktop' \| 'phone' | 'desktop' | | +| type | Type of Shell | 'light' \| 'dark' \| 'brand' | 'light' | | +| fixedHeader | Fixed header or not. Doesn't work under IE11 | boolean | false | | ### Shell.Navigation -It will tell his children whether it's collapse or not by `isCollapse` via Context. -| Param | Description | Type | Default Value | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | collapse or not | Boolean | false | -| direction | header or asider

**option**:
'hoz', 'ver' | Enum | hoz | -| align | Arrangement of Navigation when direction is hoz

**option**:
'left', 'right', 'center' | Enum | right | -| onCollapseChange | this will be triggered when collapse changed by inner icon | Function | () => {} | -| trigger | trigger of Shell.Navigation, it placed on top and left of the page, you can set `null` to remove it | ReactNode | | -| fixed | fixed or not, only worked when Shell fixedHeader is true | Boolean | false | +| Param | Description | Type | Default Value | Required | +| ---------------- | ------------------------------------------------------------------------------------------------- | ----------------------------- | ------------- | -------- | +| direction | Header or asider | 'hoz' \| 'ver' | 'hoz' | | +| collapse | Collapse or not | boolean | false | | +| align | Arrangement of Navigation when direction is hoz | 'left' \| 'right' \| 'center' | 'right' | | +| onCollapseChange | This will be triggered when collapse changed by inner icon | (collapse?: boolean) => void | func.noop | | +| trigger | Trigger of Shell.Navigation, it placed on top and left of the page, you can set null to remove it | ReactNode | - | | +| fixed | Fixed or not, only worked when Shell fixedHeader is true | boolean | false | | ### Shell.LocalNavigation -| Param | Description | Type | Default Value | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | collapse or not | Boolean | false | -| onCollapseChange | this will be triggered when collapse changed by inner icon | Function | () => {} | + +| Param | Description | Type | Default Value | Required | +| ---------------- | ---------------------------------------------------------- | ---------------------------- | ------------- | -------- | +| collapse | Collapse or not | boolean | false | | +| onCollapseChange | This will be triggered when collapse changed by inner icon | (collapse?: boolean) => void | func.noop | | ### Shell.ToolDock -| Param | Description | Type | Default Value | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | collapse or not | Boolean | false | -| onCollapseChange | this will be triggered when collapse changed by inner icon | Function | () => {} | -| fixed | fixed or not, only worked when Shell fixedHeader is true | Boolean | false | + +| Param | Description | Type | Default Value | Required | +| ---------------- | ---------------------------------------------------------- | ---------------------------- | ------------- | -------- | +| collapse | Collapse or not | boolean | false | | +| onCollapseChange | This will be triggered when collapse changed by inner icon | (collapse?: boolean) => void | func.noop | | +| fixed | Fixed or not, only worked when Shell fixedHeader is true | boolean | false | | ### Shell.Ancillary -| Param | Description | Type | Default Value | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | collapse or not | Boolean | false | -| onCollapseChange | this will be triggered when collapse changed by inner icon | Function | () => {} | + +| Param | Description | Type | Default Value | Required | +| ---------------- | ---------------------------------------------------------- | ---------------------------- | ------------- | -------- | +| collapse | Collapse or not | boolean | false | | +| onCollapseChange | This will be triggered when collapse changed by inner icon | (collapse?: boolean) => void | func.noop | | diff --git a/components/shell/__docs__/index.md b/components/shell/__docs__/index.md index 3712a45047..2a043a95f1 100644 --- a/components/shell/__docs__/index.md +++ b/components/shell/__docs__/index.md @@ -10,66 +10,68 @@ 框架组件,仅支持IE10+。 ## 何时使用 -- Shell 是整个应用的基础结构框架。 -- 它体现应用的结构形式和承载应用的基本能力,让用户可以在同一套框架下完成自己所有的操作。 + +- Shell 是整个应用的基础结构框架。 +- 它体现应用的结构形式和承载应用的基本能力,让用户可以在同一套框架下完成自己所有的操作。 ## 如何使用 -- Shell 应该根据业务实际诉求的复杂度进行配置; -- 同一个应用统一使用一套 Shell 框架,避免出现混乱问题。 +- Shell 应该根据业务实际诉求的复杂度进行配置; +- 同一个应用统一使用一套 Shell 框架,避免出现混乱问题。 ## API ### Shell -| 参数 | 说明 | 类型 | 默认值 | -| -------------------- | ------------ | ----------------- | ------------------ | -| device | 预设屏幕宽度,会影响`Navigation` `LocalNavigation` `Ancillary`等是否占据空间

**可选值**:
'phone', 'tablet', 'desktop' | Enum | desktop | -| type | 样式类型,分浅色主题、深色主题、主题色主题

**可选值**:
'light', 'dark', 'brand' | Enum | light | -| fixedHeader | 是否固定Header,采用sticky布局,不支持 IE11 | Boolean | false | -### Shell.Navigation -向子组件透传 isCollapse 的Context,表示当前是否处于折叠状态 +| 参数 | 说明 | 类型 | 默认值 | 是否必填 | +| ----------- | ---------------------------------------------------------------------- | -------------------------------- | --------- | -------- | +| device | 预设屏幕宽度,会影响Navigation LocalNavigation Ancillary等是否占据空间 | 'tablet' \| 'desktop' \| 'phone' | 'desktop' | | +| type | 样式类型,分浅色主题、深色主题、主题色主题 | 'light' \| 'dark' \| 'brand' | 'light' | | +| fixedHeader | 是否固定Header,采用sticky布局,不支持 IE11 | boolean | false | | -| 参数 | 说明 | 类型 | 默认值 | -| -------------------- | ------------ | ----------------- | ------------------ | -| direction | 方向

**可选值**:
'hoz', 'ver' | Enum | hoz | -| collapse | 是否折叠(折叠成只有icon状态) | Boolean | false | -| align | 横向模式下,导航排布的位置

**可选值**:
'left', 'right', 'center' | Enum | right | -| onCollapseChange | 默认按钮触发的展开收起状态 | Function | () => {} | -| trigger | 菜单展开、收起的触发元素,默认在左上角,不想要可以设置 `null` 来去掉 | ReactNode | | -| fixed | 是否固定,且需要在在 Shell fixedHeader时生效 | Boolean | false | +### Shell.Navigation +| 参数 | 说明 | 类型 | 默认值 | 是否必填 | +| ---------------- | ------------------------------------------------------------------ | ----------------------------- | --------- | -------- | +| direction | 方向 | 'hoz' \| 'ver' | 'hoz' | | +| collapse | 是否折叠(折叠成只有icon状态) | boolean | false | | +| align | 横向模式下,导航排布的位置 | 'left' \| 'right' \| 'center' | 'right' | | +| onCollapseChange | 默认按钮触发的展开收起状态 | (collapse?: boolean) => void | func.noop | | +| trigger | 菜单展开、收起的触发元素,默认在左上角,不想要可以设置 null 来去掉 | ReactNode | - | | +| fixed | 是否固定,且需要在在 Shell fixedHeader时生效 | boolean | false | | ### Shell.LocalNavigation -| 参数 | 说明 | 类型 | 默认值 | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | 是否折叠(完全收起) | Boolean | false | -| onCollapseChange | 默认按钮触发的展开收起状态 | Function | () => {} | + +| 参数 | 说明 | 类型 | 默认值 | 是否必填 | +| ---------------- | -------------------------- | ---------------------------- | --------- | -------- | +| collapse | 是否折叠(完全收起) | boolean | false | | +| onCollapseChange | 默认按钮触发的展开收起状态 | (collapse?: boolean) => void | func.noop | | ### Shell.ToolDock -| 参数 | 说明 | 类型 | 默认值 | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | 是否折叠(完全收起) | Boolean | false | -| onCollapseChange | 默认按钮触发的展开收起状态 | Function | () => {} | -| fixed | 是否固定,且需要在在 Shell fixedHeader时生效 | Boolean | false | + +| 参数 | 说明 | 类型 | 默认值 | 是否必填 | +| ---------------- | -------------------------------------------- | ---------------------------- | --------- | -------- | +| collapse | 是否折叠(完全收起) | boolean | false | | +| onCollapseChange | 默认按钮触发的展开收起状态 | (collapse?: boolean) => void | func.noop | | +| fixed | 是否固定,且需要在在 Shell fixedHeader时生效 | boolean | false | | ### Shell.Ancillary -| 参数 | 说明 | 类型 | 默认值 | -| -------------------- | ------------ | ----------------- | ------------------ | -| collapse | 是否折叠(完全收起) | Boolean | false | -| onCollapseChange | 默认按钮触发的展开收起状态 | Function | () => {} | +| 参数 | 说明 | 类型 | 默认值 | 是否必填 | +| ---------------- | -------------------------- | ---------------------------- | --------- | -------- | +| collapse | 是否折叠(完全收起) | boolean | false | | +| onCollapseChange | 默认按钮触发的展开收起状态 | (collapse?: boolean) => void | func.noop | | ## FAQ - ### 有侧边栏的情况下,如何去掉左上角的side bar 展开、收起触发器? + 设置 `` -````jsx +```jsx - + @@ -84,6 +86,6 @@
-```` +``` -其中 `` 采用Grid布局, 其他均为 Flex布局。 \ No newline at end of file +其中 `` 采用Grid布局, 其他均为 Flex布局。 diff --git a/components/shell/__docs__/theme/index.tsx b/components/shell/__docs__/theme/index.tsx index a3c4d0025b..f4c97c5086 100644 --- a/components/shell/__docs__/theme/index.tsx +++ b/components/shell/__docs__/theme/index.tsx @@ -1,4 +1,6 @@ -import { Demo, DemoGroup, DemoHead, initDemo } from '../../../demo-helper'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Demo, DemoGroup, initDemo, type DemoProps } from '../../../demo-helper'; import Shell from '../../index'; import Nav from '../../../nav'; import Search from '../../../search'; @@ -11,6 +13,86 @@ import '../../style'; import '../../../search/style'; import '../../../nav/style'; +interface ShellThemeProps { + type: 'light' | 'dark' | 'brand'; + i18n: { + [key: string]: string; + }; + demoFunction: { + device: { + value: 'phone' | 'tablet' | 'desktop'; + label: string; + enum: Array<{ label: string; value: string }>; + }; + navigation: { + value?: 'hoz' | 'ver'; + label: string; + enum: Array<{ label: string; value: string }>; + }; + navigationType: { + value?: 'normal' | 'primary' | 'secondary' | 'line'; + label: string; + enum: Array<{ label: string; value: string }>; + }; + localNav: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + localNavType?: { + value?: 'normal' | 'primary' | 'secondary' | 'line'; + label: string; + enum: Array<{ label: string; value: string }>; + }; + branding: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + actions: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + appbar: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + ancillary: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + tooldock: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + footer: { + value: string; + label: string; + enum: Array<{ label: string; value: string }>; + }; + }; +} + +interface FunctionDemoProps { + title: DemoProps['title']; + type: ShellThemeProps['type']; + locale: ShellThemeProps['i18n']; + shellRender: ( + type: ShellThemeProps['type'], + locale: ShellThemeProps['i18n'], + demoFunction: ShellThemeProps['demoFunction'] + ) => React.ReactNode; +} + +interface FunctionDemoState { + // demoFunction: DemoProps['demoFunction'] + demoFunction: ShellThemeProps['demoFunction']; +} + /* eslint-disable */ const i18nMap = { 'zh-cn': { @@ -26,7 +108,7 @@ const i18nMap = { brand: 'Template 3 - brand', }, }; -class RenderShell extends React.Component { +class RenderShell extends React.Component { render() { const { type, i18n, demoFunction } = this.props; const device = demoFunction.device.value; @@ -34,7 +116,7 @@ class RenderShell extends React.Component { let globalNavType = demoFunction.navigationType.value, // localNavType = demoFunction.localNavType.value, // globalHozNavType = 'normal', - localNavType = 'normal', + localNavType: 'normal' | 'primary' | 'secondary' | 'line' = 'normal', logoStyle = {}, shellStyle = {}; @@ -78,7 +160,7 @@ class RenderShell extends React.Component { App Name ) : null} - + {/* @ts-expect-error navigation.value 不会为'false',此判断无意义 */} {demoFunction.navigation.value !== 'false' ? (