-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5db9a5
commit 70be5aa
Showing
28 changed files
with
343 additions
and
233 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Input 输入框 | ||
|
||
> 一个用于输入和编辑文本的组件。 | ||
使用 `import { IInput } from "@/components";` | ||
|
||
源码 `components/widgets/input` | ||
|
||
## 何时使用 | ||
|
||
* 传达用户可以采取的操作,触发相应的业务逻辑。 | ||
|
||
## 代码演示 | ||
|
||
### 基本用法 | ||
|
||
<code src='@examples/input/basic' /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { produce } from 'immer'; | ||
import { create } from 'zustand'; | ||
|
||
import { isEmpty, isString } from '@busymango/is-esm'; | ||
import { VariantControl } from '@examples/widgets'; | ||
|
||
import type { IControlWrapProps } from '@/components'; | ||
import { IControlWrap, IFlex, IInput, ISignLine } from '@/components'; | ||
|
||
type InputStore = { | ||
text?: string | null; | ||
clear?: () => void; | ||
change?: (text?: string | React.ChangeEvent<HTMLInputElement>) => void; | ||
}; | ||
|
||
const useInputStore = create<InputStore>((set) => ({ | ||
clear: () => { | ||
set( | ||
produce((state: InputStore) => { | ||
state.text = null; | ||
}) | ||
); | ||
}, | ||
change: (event) => { | ||
set( | ||
produce((state: InputStore) => { | ||
if (isString(event)) { | ||
state.text = event; | ||
} | ||
if (!isString(event)) { | ||
state.text = event?.target.value; | ||
} | ||
}) | ||
); | ||
}, | ||
})); | ||
|
||
const App: React.FC = () => { | ||
const { text, clear, change } = useInputStore(); | ||
|
||
const closeable = !isEmpty(text); | ||
|
||
return ( | ||
<VariantControl | ||
variants={ | ||
[ | ||
'bordered', | ||
'filled', | ||
'standard', | ||
] satisfies IControlWrapProps['variant'][] | ||
} | ||
> | ||
{({ variant }) => ( | ||
<IFlex> | ||
<IControlWrap | ||
isSuffixClickable={closeable} | ||
suffix={ | ||
<ISignLine | ||
animate={{ opacity: closeable ? 1 : 0 }} | ||
type="cross" | ||
/> | ||
} | ||
variant={variant} | ||
onSuffixClick={clear} | ||
> | ||
<IInput | ||
placeholder="占位文本" | ||
value={text} | ||
width="100%" | ||
onChange={change} | ||
/> | ||
</IControlWrap> | ||
</IFlex> | ||
)} | ||
</VariantControl> | ||
); | ||
}; | ||
|
||
export default App; |
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,4 @@ | ||
.wrap { | ||
display: grid; | ||
place-items: center; | ||
} |
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,31 @@ | ||
import classNames from 'classnames'; | ||
import { AnimatePresence } from 'framer-motion'; | ||
|
||
import { FloatingPortal } from '@floating-ui/react'; | ||
|
||
import { container } from '@/init'; | ||
import type { ReactCFC } from '@/models'; | ||
import { iFindElement } from '@/utils'; | ||
|
||
import type { IBackdropProps } from './models'; | ||
import { IOverlay } from './overlay'; | ||
|
||
import * as styles from './backdrop.scss'; | ||
|
||
export const IBackdrop: ReactCFC<IBackdropProps> = ({ | ||
open, | ||
children, | ||
className, | ||
root = container, | ||
...others | ||
}) => ( | ||
<FloatingPortal root={iFindElement(root)}> | ||
<AnimatePresence> | ||
{open && ( | ||
<IOverlay className={classNames(styles.wrap, className)} {...others}> | ||
{children} | ||
</IOverlay> | ||
)} | ||
</AnimatePresence> | ||
</FloatingPortal> | ||
); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +1 @@ | ||
import classNames from 'classnames'; | ||
import { AnimatePresence } from 'framer-motion'; | ||
|
||
import { FloatingPortal } from '@floating-ui/react'; | ||
|
||
import { container } from '@/init'; | ||
import type { ReactCFC } from '@/models'; | ||
import { iFindElement } from '@/utils'; | ||
|
||
import { IOverlay } from '../overlay'; | ||
import type { IBackdropProps } from './models'; | ||
|
||
import * as styles from './index.scss'; | ||
|
||
export const IBackdrop: ReactCFC<IBackdropProps> = ({ | ||
open, | ||
children, | ||
className, | ||
root = container, | ||
...others | ||
}) => ( | ||
<FloatingPortal root={iFindElement(root)}> | ||
<AnimatePresence> | ||
{open && ( | ||
<IOverlay className={classNames(styles.wrap, className)} {...others}> | ||
{children} | ||
</IOverlay> | ||
)} | ||
</AnimatePresence> | ||
</FloatingPortal> | ||
); | ||
export * from './backdrop'; |
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import type { ReactTargetFunc } from '@/models'; | ||
import type { HTMLMotionProps } from 'framer-motion'; | ||
|
||
import type { IOverlayProps } from '../../overlay'; | ||
import type { ReactTargetType } from '@/models'; | ||
|
||
export interface IOverlayProps extends HTMLMotionProps<'div'> { | ||
/** | ||
* overlay will lock scrolling on the document body if is false. | ||
* @default false | ||
*/ | ||
scroll?: boolean; | ||
} | ||
|
||
export interface IBackdropProps extends IOverlayProps { | ||
open?: boolean; | ||
/** | ||
* 浮层默认渲染到 root 上,也可以使用此方法指定根节点。 | ||
*/ | ||
root?: ReactTargetFunc; | ||
root?: ReactTargetType; | ||
} |
5 changes: 1 addition & 4 deletions
5
src/components/widgets/overlay/index.scss → src/components/widgets/backdrop/overlay.scss
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
.wrap { | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
inset: 0; | ||
overflow: auto; | ||
position: fixed; | ||
} |
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
Oops, something went wrong.