Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fixed overlay zIndex is not effective, and extract types of dialog, overlay, fixednav, popup, toast #2954

Merged
merged 22 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions scripts/build-taro.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { generate } from './build-theme-typings.mjs'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const isTypesTaro = (name, type) => {
return name.indexOf(type) > -1
}

// 写文件
async function dest(file, content) {
const dir = dirname(file)
Expand All @@ -31,7 +35,7 @@ async function dest(file, content) {
await writeFile(file, content)
}

const transform = (file, api) => {
const transform = (file, api, replace) => {
const j = api.jscodeshift.withParser('ts')
const ast = j(file.source)
const imports = ast.find(j.ImportDeclaration)
Expand All @@ -45,7 +49,10 @@ const transform = (file, api) => {
: ''
if (!path.node.source) return
if (!alias) {
path.node.source.value = path.node.source.value.replace('.taro', '')
// 处理这里,文件引入中的相对路径下的types的引入。
path.node.source.value = (!replace || replace && !isTypesTaro(path.node.source.value, 'types.taro'))
? path.node.source.value.replace('.taro', '')
: path.node.source.value
return
}
const dir = join(__dirname, alias.replace('@/', '../src/'))
Expand Down Expand Up @@ -170,8 +177,12 @@ async function buildDeclaration() {
path: join(__dirname, '../', file).replace('/dist/types', ''),
},
{ jscodeshift: j },
true
)
const to = file.replace('dist/types/src', '').replace('.taro', '')

// 修改文件名,除 types.taro 不改之外,其他都修改。
let to = file.replace('dist/types/src', '')
to = isTypesTaro(to, 'types.taro') ? to : to.replace('.taro', '')
await dest(join('dist/es', to), result)
await dest(join('dist/cjs', to), result)
}
Expand Down
4 changes: 2 additions & 2 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
"dd": true
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "FixedNav",
"type": "component",
"cName": "悬浮导航",
Expand All @@ -323,7 +323,7 @@
"show": true,
"taro": true,
"author": "Ymm0008",
"dd": false
"dd": true
},
{
"version": "3.0.0",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`Cascader > visible true 1`] = `
<div>
<div
class="nut-overlay"
style="--nutui-overlay-zIndex: 1000;"
style="z-index: 1000;"
/>
<div
class="nut-popup nut-popup-round nut-popup-bottom"
Expand Down
7 changes: 5 additions & 2 deletions src/packages/cascader/cascader.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import React, {
import classNames from 'classnames'
import { Loading, Check } from '@nutui/icons-react-taro'
import { ScrollView, View } from '@tarojs/components'
import { Popup, PopupProps } from '@/packages/popup/popup.taro'
import Popup, {
PopupProps,
CloseIconPosition,
} from '@/packages/popup/index.taro'
import { Tabs } from '@/packages/tabs/tabs.taro'
import Tree, { convertListToOptions } from './utils'
import {
Expand Down Expand Up @@ -57,7 +60,7 @@ export interface CascaderProps
optionKey: CascaderOptionKey
format: Record<string, string | number | null>
closeable: boolean
closeIconPosition: string
closeIconPosition: CloseIconPosition
closeIcon: ReactNode
lazy: boolean
onLoad: (node: any, resolve: any) => void
Expand Down
4 changes: 2 additions & 2 deletions src/packages/cascader/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
} from 'react'
import classNames from 'classnames'
import { Loading, Check } from '@nutui/icons-react'
import { Popup, PopupProps } from '@/packages/popup/popup'
import Popup, { PopupProps, CloseIconPosition } from '@/packages/popup/index'
import { Tabs } from '@/packages/tabs/tabs'
import Tree, { convertListToOptions } from './utils'
import {
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface CascaderProps
optionKey: CascaderOptionKey
format: Record<string, string | number | null>
closeable: boolean
closeIconPosition: string
closeIconPosition: CloseIconPosition
closeIcon: ReactNode
lazy: boolean
onLoad: (node: any, resolve: any) => void
Expand Down
2 changes: 0 additions & 2 deletions src/packages/configprovider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export type NutCSSVariables =
| 'nutuiColorPrimaryDisabled'
| 'nutuiColorPrimaryDisabledSpecial'
| 'nutuiColorPrimaryLightPressed'
| 'nutuiBrand3'
| 'nutuiBrand1'
| 'nutuiColorPrimaryIcon'
| 'nutuiColorPrimaryIconDisabled'
| 'nutuiColorPrimarySpecialdisabled'
Expand Down
58 changes: 0 additions & 58 deletions src/packages/dialog/config.ts

This file was deleted.

35 changes: 11 additions & 24 deletions src/packages/dialog/confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
import React from 'react'
import { Dialog } from './dialog'
import { destroyList, DialogConfirmProps, DialogReturnProps } from './config'
import { destroyList, DialogConfirmProps, DialogReturnProps } from './types'
import { render as reactRender, unmount } from '@/utils/render'

function ConfirmDialog(props: DialogConfirmProps) {
type DialogConfirmNativeProps = Partial<DialogConfirmProps>
function ConfirmDialog(props: DialogConfirmNativeProps) {

Check warning on line 7 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L7

Added line #L7 was not covered by tests
return <Dialog {...props}>{props.content}</Dialog>
}

// 如果是消息提示型弹出框,那么只有确认按钮
export const normalizeConfig = (
config: DialogConfirmProps
): DialogConfirmProps => {
if (config.isNotice) {
let { icon } = config
if (!icon && icon !== null) {
switch (config.noticeType) {
case 'alert':
icon = ''
break
default:
break
}
}
config.hideCancelButton = true
}
config: DialogConfirmNativeProps
): DialogConfirmNativeProps => {
config.hideCancelButton = config.isNotice

Check warning on line 15 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L13-L15

Added lines #L13 - L15 were not covered by tests
return config
}

const confirm = (
config: DialogConfirmProps,
renderFunc?: (props: DialogConfirmProps) => void
config: DialogConfirmNativeProps,
renderFunc?: (props: DialogConfirmNativeProps) => void

Check warning on line 21 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L20-L21

Added lines #L20 - L21 were not covered by tests
): DialogReturnProps => {
const div = document.createElement('div')
document.body.appendChild(div)

let dialogConfig: DialogConfirmProps = {
let dialogConfig: DialogConfirmNativeProps = {

Check warning on line 26 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L26

Added line #L26 was not covered by tests
...config,
visible: false,
}

const render = (props: DialogConfirmProps, callback?: () => any) => {
const render = (props: DialogConfirmNativeProps, callback?: () => any) => {

Check warning on line 31 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L31

Added line #L31 was not covered by tests
reactRender(<ConfirmDialog {...props} onCancel={() => onCancel()} />, div)
callback && callback()
}
Expand Down Expand Up @@ -97,13 +86,11 @@
})
}

const update = (newConfig: DialogConfirmProps) => {
const update = (newConfig: DialogConfirmNativeProps) => {

Check warning on line 89 in src/packages/dialog/confirm.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/dialog/confirm.tsx#L89

Added line #L89 was not covered by tests
dialogConfig = {
...dialogConfig,
title: config.title, // 避免 newConfig 未传递 title 时,icon 出现多个的问题
...newConfig,
}

dialogConfig = normalizeConfig(dialogConfig)
renderFunction(dialogConfig)
}
Expand Down
58 changes: 28 additions & 30 deletions src/packages/dialog/content.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, { FunctionComponent, ReactNode, HTMLAttributes } from 'react'
import React, { FunctionComponent, HTMLAttributes } from 'react'
import classNames from 'classnames'
import { ITouchEvent, View } from '@tarojs/components'
import { BasicComponent } from '@/utils/typings'
import { View, ITouchEvent } from '@tarojs/components'
import { ContentProps } from './types.taro'

interface ContentProps extends BasicComponent {
visible: boolean
title: ReactNode
header: ReactNode
footer: ReactNode
close: ReactNode
footerDirection: string
onClick: (event: ITouchEvent) => void
export const defaultContentProps: ContentProps = {
visible: false,
title: '',
header: '',
footer: '',
close: '',
footerDirection: 'horizontal',
onClick: () => {},
}

export const Content: FunctionComponent<
Expand All @@ -24,39 +24,39 @@ export const Content: FunctionComponent<
footer,
close,
footerDirection,
onClick,
children,
} = props
onClick,
} = { ...defaultContentProps, ...props }

const classPrefix = 'nut-dialog'

const renderHeader = () => {
return title ? (
<View className={`${classPrefix}-header`}>{title}</View>
) : null
return title && <View className={`${classPrefix}-header`}>{title}</View>
}

const renderFooter = () => {
return footer ? (
<View
className={classNames(`${classPrefix}-footer`, {
[footerDirection as any]: footerDirection,
})}
>
{footer}
</View>
) : null
return (
footer && (
<View
className={classNames(`${classPrefix}-footer`, {
[footerDirection]: footerDirection,
})}
>
{footer}
</View>
)
)
}

const handleClick = (e: any) => {
const handleClick = (e: ITouchEvent) => {
onClick && onClick(e)
}

return (
<View
className={classNames(`${classPrefix}-outer`, props.className)}
style={props.style}
onClick={(e) => handleClick(e)}
onClick={(e: ITouchEvent) => handleClick(e)}
>
{close}
{header}
Expand All @@ -65,9 +65,7 @@ export const Content: FunctionComponent<
style={{ display: visible ? 'flex' : 'none' }}
>
{renderHeader()}
<View className={`${classPrefix}-content`}>
<>{children}</>
</View>
<View className={`${classPrefix}-content`}>{children}</View>
{renderFooter()}
</View>
</View>
Expand Down
Loading
Loading