| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- import React, { useState } from 'react';
- import Popover from '../index';
- import { strings } from '@douyinfe/semi-foundation/tooltip/constants';
- import { Button, Input, Table, IconButton, Modal, Tag } from '@douyinfe/semi-ui';
- import SelectInPopover from './SelectInPopover';
- import BtnClose from './BtnClose';
- import PopRight from './PopRight';
- import NestedPopover from './NestedPopover';
- import ArrowPointAtCenter from './ArrowPointAtCenter';
- import { IconDelete } from '@douyinfe/semi-icons';
- export default {
- title: 'Popover',
- parameters: {
- chromatic: { disableSnapshot: true },
- },
- }
- let style = {
- display: 'inline-block',
- padding: '20px',
- };
- export const _Popover = () => (
- <div>
- <div style={style}>
- <Popover content="ies vigo" title="bytedance" position="bottom" visible={true} showArrow>
- bottom hover
- </Popover>
- </div>
- <div style={style}>
- <Popover content="ies vigo" title="bytedance" trigger="click" position="bottom">
- bottom click
- </Popover>
- </div>
- <div style={style}>
- <Popover content="ies vigo" title="bytedance" trigger="click" position="right">
- <Button>Pos:right, trigger: Click</Button>
- </Popover>
- </div>
- <div style={style}>
- <Popover
- content={<Button type="warning">btn</Button>}
- title="bytedance"
- trigger="click"
- position="right"
- >
- content is Node
- </Popover>
- </div>
- <div style={style}>
- <Popover content={<Input />} title="bytedance" trigger="click" position="right">
- content is Node
- </Popover>
- </div>
- </div>
- );
- _Popover.story = {
- name: 'popover',
- };
- export const Positions = () => (
- <div
- style={{
- width: 480,
- height: 360,
- boxSizing: 'content-box',
- padding: '150px 50px',
- display: 'flex',
- flexWrap: 'wrap',
- justifyContent: 'space-evenly',
- }}
- >
- {strings.POSITION_SET.map(pos => (
- <Popover
- key={pos}
- content={
- <div
- style={{
- padding: 20,
- }}
- >
- <p>Hi Bytedancer!</p>
- </div>
- }
- trigger="click"
- position={pos}
- >
- <Button key={pos}>{pos}</Button>
- </Popover>
- ))}
- </div>
- );
- Positions.story = {
- name: 'positions',
- };
- export const PopConfirm = () => (
- <div>
- <div style={style}>
- <Popover isConfirmMode content="hi byteddance ies">
- <a>IconDelete</a>
- </Popover>
- </div>
- </div>
- );
- PopConfirm.story = {
- name: 'popConfirm',
- };
- class Demo extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- visible: false,
- };
- this.changeVisible = this.changeVisible.bind(this);
- this.renderContent = this.renderContent.bind(this);
- }
- changeVisible(visible = true) {
- this.setState({
- visible,
- });
- }
- renderContent() {
- return (
- <>
- <p>hi byteddance ies</p>
- <Button onClick={() => this.changeVisible(false)}>cancel</Button>
- <Button onClick={() => this.changeVisible(false)}>confirm</Button>
- </>
- );
- }
- render() {
- const content = this.renderContent();
- const { visible } = this.state;
- return (
- <Popover trigger="custom" content={content} visible={visible} position="bottomLeft">
- <Button onClick={() => this.changeVisible(true)}>show Popover</Button>
- </Popover>
- );
- }
- }
- export const PopoverCustomVisible = () => <Demo />;
- PopoverCustomVisible.story = {
- name: 'popover custom visible',
- };
- CompositeComponent.story = { name: '复合组件' };
- export function CompositeComponent() {
- class TableApp extends React.Component {
- constructor(props) {
- super(props);
- this.raw = [
- {
- key: '1',
- name: 'John Brown',
- age: 32,
- address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
- },
- {
- key: '2',
- name: 'Jim Green',
- age: 42,
- address: 'London No. 1 Lake Park',
- },
- {
- key: '3',
- name: 'Joe Black',
- age: 32,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '4',
- name: 'Disabled User',
- age: 99,
- address: 'Sidney No. 1 Lake Park',
- },
- ];
- this.state = {
- dataSource: [...this.raw],
- modalVisible: false,
- columns: [
- {
- title: 'Name',
- dataIndex: 'name',
- render: text => <a href="javascript:;">{text}</a>,
- },
- {
- title: 'Age',
- dataIndex: 'age',
- },
- {
- title: 'Address',
- dataIndex: 'address',
- },
- {
- title: 'Operation',
- render: (text, record) => (
- <div>
- <Button icon={<IconDelete />} onClick={() => this.removeRecord(record.key)} />
- <Button onClick={() => this.toggleModal(true)}>编辑</Button>
- </div>
- ),
- },
- ],
- };
- }
- removeRecord(key) {
- let dataSource = [...this.state.dataSource];
- if (key != null) {
- let idx = dataSource.findIndex(data => data.key === key); // console.log(key, dataSource, idx);
- if (idx > -1) {
- dataSource.splice(idx, 1);
- this.setState({
- dataSource,
- });
- }
- }
- }
- resetData() {
- let dataSource = [...this.raw];
- this.setState({
- dataSource,
- });
- }
- toggleModal = modalVisible => {
- this.setState({
- modalVisible,
- });
- };
- renderModalContent = () => {
- const { modalVisible } = this.state;
- return (
- <Modal
- visible={modalVisible}
- onCancel={() => this.toggleModal(false)}
- onOk={() => this.toggleModal(false)}
- >
- <p>This is a modal with customized styles.</p>
- <p>More content...</p>
- <Popover
- content={
- <div>
- <Button>按钮1</Button>
- <Button>按钮2</Button>
- </div>
- }
- >
- <Button>hover</Button>
- </Popover>
- </Modal>
- );
- };
- render() {
- let { columns, dataSource } = this.state;
- return (
- <>
- <Button onClick={() => this.resetData()}>Reset</Button>
- <Table columns={columns} dataSource={dataSource} pagination={false} />
- {this.renderModalContent()}
- </>
- );
- }
- }
- return <TableApp />;
- };
- const ScrollDemo = function ScrollDemo(props = {}) {
- const tops = [
- ['topLeft', 'TL'],
- ['top', 'Top'],
- ['topRight', 'TR'],
- ];
- const lefts = [
- ['leftTop', 'LT'],
- ['left', 'Left'],
- ['leftBottom', 'LB'],
- ];
- const rights = [
- ['rightTop', 'RT'],
- ['right', 'Right'],
- ['rightBottom', 'RB'],
- ];
- const bottoms = [
- ['bottomLeft', 'BL'],
- ['bottom', 'Bottom'],
- ['bottomRight', 'BR'],
- ];
- const { tagstyle, ...restProps } = props;
- return (
- <div
- style={{
- paddingLeft: 40,
- }}
- >
- <div
- style={{
- marginLeft: 40,
- whiteSpace: 'nowrap',
- }}
- >
- {tops.map((pos, index) => (
- <Popover
- content={
- <article>
- <p>hi bytedance</p>
- <p>hi bytedance</p>
- </article>
- }
- position={Array.isArray(pos) ? pos[0] : pos}
- key={index}
- trigger={'click'}
- {...restProps}
- >
- <Tag style={tagstyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
- </Popover>
- ))}
- </div>
- <div
- style={{
- width: 40,
- float: 'left',
- }}
- >
- {lefts.map((pos, index) => (
- <Popover
- content={
- <article>
- <p>hi bytedance</p>
- <p>hi bytedance</p>
- </article>
- }
- position={Array.isArray(pos) ? pos[0] : pos}
- key={index}
- trigger={'click'}
- {...restProps}
- >
- <Tag style={tagstyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
- </Popover>
- ))}
- </div>
- <div
- style={{
- width: 40,
- marginLeft: 180,
- }}
- >
- {rights.map((pos, index) => (
- <Popover
- content={
- <article>
- <p>hi bytedance</p>
- <p>hi bytedance</p>
- </article>
- }
- position={Array.isArray(pos) ? pos[0] : pos}
- key={index}
- trigger={'click'}
- {...restProps}
- >
- <Tag style={tagstyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
- </Popover>
- ))}
- </div>
- <div
- style={{
- marginLeft: 40,
- clear: 'both',
- whiteSpace: 'nowrap',
- }}
- >
- {bottoms.map((pos, index) => (
- <Popover
- content={
- <article>
- <p>hi bytedance</p>
- <p>hi bytedance</p>
- </article>
- }
- position={Array.isArray(pos) ? pos[0] : pos}
- key={index}
- trigger={'click'}
- {...restProps}
- >
- <Tag style={tagstyle}>{Array.isArray(pos) ? pos[1] : pos}</Tag>
- </Popover>
- ))}
- </div>
- </div>
- );
- };
- export const ScrollPopover = () => {
- return (
- <>
- <div id="wrapper">
- <div
- style={{
- height: '200vh',
- width: '200vw',
- padding: 50,
- }}
- >
- 滚动到下面
- </div>
- </div>
- <div
- style={{
- padding: 1200,
- }}
- >
- <ScrollDemo
- content={
- <article
- style={{
- padding: 12,
- }}
- >
- <p>hi bytedance</p>
- <p>hi bytedance</p>
- </article>
- }
- />
- </div>
- </>
- );
- };
- ScrollPopover.story = {
- name: 'scroll popover',
- };
- export const WithArrow = () => (
- <div>
- <div
- style={{
- padding: 120,
- }}
- >
- <ScrollDemo showArrow />
- </div>
- <div
- style={{
- padding: 120,
- }}
- >
- <ScrollDemo
- showArrow
- tagstyle={{
- minHeight: 80,
- minWidth: 120,
- }}
- />
- </div>
- <div
- style={{
- padding: 120,
- }}
- >
- <ScrollDemo
- showArrow
- tagstyle={{
- minHeight: 80,
- minWidth: 120,
- }}
- style={{
- backgroundColor: 'green',
- }}
- />
- </div>
- </div>
- );
- WithArrow.story = {
- name: 'with arrow',
- };
- export const NoContent = () => (
- <div>
- <div
- style={{
- padding: 50,
- }}
- >
- <ScrollDemo content={<div></div>} />
- </div>
- <div
- style={{
- padding: 50,
- }}
- >
- <ScrollDemo showArrow content={''} />
- </div>
- <div
- style={{
- padding: 50,
- }}
- >
- <ScrollDemo
- showArrow
- content={''}
- tagstyle={{
- height: 80,
- minWidth: 100,
- }}
- style={{
- padding: 20,
- }}
- />
- </div>
- </div>
- );
- NoContent.story = {
- name: 'no content',
- };
- export const _SelectInPopover = () => (
- <div
- style={{
- padding: 50,
- }}
- >
- <SelectInPopover />
- </div>
- );
- _SelectInPopover.story = {
- name: 'select in popover',
- };
- export const CloseBtnInPopover = () => <BtnClose />;
- CloseBtnInPopover.story = {
- name: 'close btn in popover',
- };
- export const PopoverFloatRight = () => <PopRight />;
- PopoverFloatRight.story = {
- name: 'popover float right',
- };
- export const NestedPopoverDemo = () => <NestedPopover />;
- NestedPopoverDemo.story = {
- name: 'nested popover'
- }
- export const ArrowPointAtCenterDemo = () => <ArrowPointAtCenter />;
- ArrowPointAtCenterDemo.story = {
- name: 'arrow point at center'
- }
|