Skip to content

Commit

Permalink
chore(portal-context): 改写名字代码 (#3060)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanjinping committed Dec 17, 2024
1 parent b163677 commit 51cdccc
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 97 deletions.
16 changes: 8 additions & 8 deletions .changeset/little-rabbits-change.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
"@hi-ui/core": patch
"@hi-ui/container-context": patch
"@hi-ui/drawer": patch
"@hi-ui/hiui": patch
"@hi-ui/loading": patch
"@hi-ui/modal": patch
"@hi-ui/preview": patch
"@hi-ui/provider": patch
"@hi-ui/core": minor
"@hi-ui/container-context": minor
"@hi-ui/drawer": minor
"@hi-ui/hiui": minor
"@hi-ui/loading": minor
"@hi-ui/modal": minor
"@hi-ui/preview": minor
"@hi-ui/provider": minor
---

feat(container-context): add container package (#3060)
2 changes: 1 addition & 1 deletion packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"dependencies": {
"@hi-ui/core-css": "^4.1.5",
"@hi-ui/locale-context": "^4.0.8",
"@hi-ui/container-context": "^4.0.0"
"@hi-ui/portal-context": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/core/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ export type HiBaseSizeEnum = ValueOf<typeof HiBaseSizeEnum>
export { useLocaleContext, LocaleProvider } from '@hi-ui/locale-context'
export type { UseLocaleContext, LocaleProviderProps } from '@hi-ui/locale-context'

export { useContainerContext, ContainerProvider } from '@hi-ui/container-context'
export type { UseContainerContext, ContainerProviderProps } from '@hi-ui/container-context'
export { usePortalContext, PortalProvider } from '@hi-ui/portal-context'
export type { UsePortalContext, PortalProviderProps } from '@hi-ui/portal-context'
7 changes: 0 additions & 7 deletions packages/ui/container-context/CHANGELOG.md

This file was deleted.

11 changes: 0 additions & 11 deletions packages/ui/container-context/README.md

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions packages/ui/container-context/src/ContainerContext.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions packages/ui/container-context/src/ContainerProvider.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions packages/ui/container-context/src/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/ui/container-context/stories/basic.stories.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/ui/drawer/src/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { forwardRef, useCallback, useEffect } from 'react'
import { cx, getPrefixCls, getPrefixStyleVar } from '@hi-ui/classname'
import { __DEV__ } from '@hi-ui/env'
import { HiBaseHTMLProps, useContainerContext } from '@hi-ui/core'
import { HiBaseHTMLProps, usePortalContext } from '@hi-ui/core'
import { CSSTransition } from 'react-transition-group'
import { Portal } from '@hi-ui/portal'
import { useModal, UseModalProps } from '@hi-ui/modal'
Expand Down Expand Up @@ -51,7 +51,7 @@ export const Drawer = forwardRef<HTMLDivElement | null, DrawerProps>(
) => {
const [transitionVisible, transitionVisibleAction] = useToggle(false)
const [transitionExited, transitionExitedAction] = useToggle(true)
const globalContainer = useContainerContext()
const globalContainer = usePortalContext()?.container
const container = containerProp ?? globalContainer

const { rootProps, getModalProps, getModalWrapperProps } = useModal({
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/hiui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export { default as LocaleContext } from '@hi-ui/locale-context'
/**
* @deprecated Please use the `Provider` instead of it.
*/
export * from '@hi-ui/container-context'
export * from '@hi-ui/portal-context'
/**
* @deprecated Please use the `Provider` instead of it.
*/
export { default as ContainerContext } from '@hi-ui/container-context'
export { default as PortalContext } from '@hi-ui/portal-context'

export * from '@hi-ui/menu'
export { default as Menu } from '@hi-ui/menu'
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/loading/src/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CSSTransition } from 'react-transition-group'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { __DEV__ } from '@hi-ui/env'
import { Portal } from '@hi-ui/portal'
import { HiBaseHTMLProps, HiBaseSizeEnum, useContainerContext } from '@hi-ui/core'
import { HiBaseHTMLProps, HiBaseSizeEnum, usePortalContext } from '@hi-ui/core'
import { useLatestCallback } from '@hi-ui/use-latest'
import Spinner from '@hi-ui/spinner'
import { useLoading } from './use-loading'
Expand Down Expand Up @@ -38,7 +38,7 @@ export const Loading = forwardRef<null, LoadingProps>(
) => {
const { internalVisible, setInternalVisible } = useLoading({ visible, delay })

const globalContainer = useContainerContext()
const globalContainer = usePortalContext()?.container
const container = containerProp ?? globalContainer

useImperativeHandle(innerRef, () => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/modal/src/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, forwardRef, useCallback, useImperativeHandle } from 'react'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { HiBaseHTMLProps, HiBaseSizeEnum, useLocaleContext, useContainerContext } from '@hi-ui/core'
import { HiBaseHTMLProps, HiBaseSizeEnum, useLocaleContext, usePortalContext } from '@hi-ui/core'
import { __DEV__ } from '@hi-ui/env'
import { CSSTransition } from 'react-transition-group'
import { Portal } from '@hi-ui/portal'
Expand Down Expand Up @@ -74,7 +74,7 @@ export const Modal = forwardRef<HTMLDivElement | null, ModalProps>(
) => {
const i18n = useLocaleContext()

const globalContainer = useContainerContext()
const globalContainer = usePortalContext()?.container
const container = containerProp ?? globalContainer

const cancelText = isUndef(cancelTextProp) ? i18n.get('modal.cancelText') : cancelTextProp
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/portal-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `@hi-ui/portal-context`

> TODO: description
## Usage

```
const PortalContext = require('@hi-ui/portal-context');
// TODO: DEMONSTRATE API
```
5 changes: 5 additions & 0 deletions packages/ui/portal-context/__tests__/portal-context.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const PortalContext = require('../src')

describe('@hi-ui/portal-context', () => {
it('needs tests', () => {})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ContainerContext 语言上下文
# PortalContext 上下文

容器设置上下文。

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@hi-ui/container-context",
"name": "@hi-ui/portal-context",
"version": "4.0.0",
"description": "A sub-package for @hi-ui/hiui.",
"keywords": [],
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/portal-context/src/PortalContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createContext, useContext } from 'react'

export const PortalContext = createContext<UsePortalContext>(null)

export const usePortalContext = () => {
const context = useContext(PortalContext)

return context
}

export type UsePortalContext = { container?: HTMLElement | null | undefined } | null | undefined
18 changes: 18 additions & 0 deletions packages/ui/portal-context/src/PortalProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { PortalContext, UsePortalContext } from './PortalContext'
import { __DEV__ } from '@hi-ui/env'

export const PortalProvider: React.FC<PortalProviderProps> = ({ children, portal }) => {
return <PortalContext.Provider value={portal}>{children}</PortalContext.Provider>
}

export interface PortalProviderProps {
/**
* 指定 portal 的容器
*/
portal?: UsePortalContext
}

if (__DEV__) {
PortalProvider.displayName = 'PortalProvider'
}
4 changes: 4 additions & 0 deletions packages/ui/portal-context/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './PortalContext'
export * from './PortalProvider'

export { PortalProvider as default } from './PortalProvider'
16 changes: 16 additions & 0 deletions packages/ui/portal-context/stories/basic.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { useContext } from 'react'
import { PortalContext } from '../src'

/**
* @title 基础用法
*/
export const Basic = () => {
useContext(PortalContext)

return (
<>
<h1>Basic</h1>
<div className="portal-context-basic__wrap"></div>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import React from 'react'
export * from './basic.stories'

export default {
title: 'Private(暂不对外)/ContainerContext',
title: 'Private(暂不对外)/PortalContext',
decorators: [(story: Function) => <div>{story()}</div>],
}
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/ui/preview/src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Portal } from '@hi-ui/portal'
import { Watermark, WatermarkProps } from '@hi-ui/watermark'
import { CSSTransition } from 'react-transition-group'
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state'
import { HiBaseHTMLProps, useContainerContext } from '@hi-ui/core'
import { HiBaseHTMLProps, usePortalContext } from '@hi-ui/core'
import { useLatestCallback } from '@hi-ui/use-latest'
import {
ZoomInOutlined,
Expand Down Expand Up @@ -53,7 +53,7 @@ export const Preview = forwardRef<HTMLDivElement | null, PreviewProps>(
) => {
const cls = cx(prefixCls, className)

const globalContainer = useContainerContext()
const globalContainer = usePortalContext()?.container
const container = containerProp ?? globalContainer

const [active, setActive] = useUncontrolledState(defaultCurrent || 0, current, onPreviewChange)
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/provider/src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { __DEV__ } from '@hi-ui/env'
import {
LocaleProvider,
LocaleProviderProps,
ContainerProvider,
ContainerProviderProps,
PortalProvider,
PortalProviderProps,
} from '@hi-ui/core'
import { DesignSystemAccentColorEnum, DesignSystemProps } from './types'
import { createSystem, extendsTheme } from './theme'
Expand All @@ -18,7 +18,7 @@ export const Provider: React.FC<ProviderProps> & { extends: ProviderExtendsFunc
languages,
accentColor,
theme,
container,
portal,
}) => {
/**
* global css var config
Expand All @@ -37,17 +37,17 @@ export const Provider: React.FC<ProviderProps> & { extends: ProviderExtendsFunc
}, [accentColor, theme])

return (
<ContainerProvider container={container}>
<PortalProvider portal={portal}>
<LocaleProvider locale={locale} languages={languages}>
{children}
</LocaleProvider>
</ContainerProvider>
</PortalProvider>
)
}

export interface ProviderProps
extends LocaleProviderProps,
ContainerProviderProps,
PortalProviderProps,
ThemeProviderProps {}

interface ThemeProviderProps {
Expand Down

0 comments on commit 51cdccc

Please sign in to comment.