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

Button icon #443

Merged
merged 2 commits into from
Apr 30, 2024
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
8 changes: 8 additions & 0 deletions docs/drip-table/components/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export default Demo;
* hideActions: ["CSB"]
*/
import { message } from 'antd';
import * as Icons from '@ant-design/icons';
import React from "react";
import DripTable from "drip-table";

Expand Down Expand Up @@ -298,10 +299,16 @@ const Demo = () => {
overlayStyle: { maxWidth: '300px' },
overlayInnerStyle: { borderRadius: '10px' },
title: '确认要删除“{{props.record.name}}”?',
titleIcon: 'InfoCircleOutlined',
titleIconStyle: { color: '#ff4900', marginRight: '5px' },
content: '您确认要执行删除“{{props.record.name}}”这个操作吗?该操作将无法撤销!',
contentIcon: 'InfoCircleOutlined',
contentIconStyle: { color: '#ff4900', marginRight: '5px' },
placement: 'top',
cancelText: '取消',
cancelStyle: { transform: 'translateX(120%)' },
confirmText: '确认',
confirmStyle: { transform: 'translateX(-120%)' },
},
},
},
Expand All @@ -311,6 +318,7 @@ const Demo = () => {
return (
<React.Fragment>
<DripTable
icons={Icons}
schema={schema}
dataSource={dataSource}
onEvent={(event, tableInfo) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';

import { DripTableColumnSchema, DripTableRecordTypeBase, SchemaObject } from '@/types';
import { DRIP_TABLE_GENERIC_CSS_SCHEMA } from '@/utils/ajv';
import { parseReactCSS, parseThemeCSS } from '@/utils/dom';
import { safeExecute } from '@/utils/sandbox';
import Button from '@/components/react-components/button';
Expand Down Expand Up @@ -46,10 +47,28 @@ export type DTCButtonColumnSchema = DripTableColumnSchema<'button', {
*/
overlayInnerStyle?: string | Record<string, string>;
title: string;
titleIcon?: string;
/**
* 标题图标自定义样式
*/
titleIconStyle?: string | Record<string, string>;
content: string;
contentIcon?: string;
/**
* 正文图标自定义样式
*/
contentIconStyle?: string | Record<string, string>;
placement?: string;
cancelText?: string;
/**
* 取消按钮自定义样式
*/
cancelStyle?: string | Record<string, string>;
confirmText?: string;
/**
* 确认按钮自定义样式
*/
confirmStyle?: string | Record<string, string>;
};
disableFunc?: string;
visibleFunc?: string;
Expand Down Expand Up @@ -147,10 +166,46 @@ export default class DTCButton<RecordType extends DripTableRecordTypeBase> exten
],
},
title: { type: 'string' },
titleIcon: { type: 'string' },
titleIconStyle: DRIP_TABLE_GENERIC_CSS_SCHEMA,
content: { type: 'string' },
contentIcon: { type: 'string' },
contentIconStyle: DRIP_TABLE_GENERIC_CSS_SCHEMA,
placement: { type: 'string' },
cancelText: { type: 'string' },
cancelStyle: {
anyOf: [
{ type: 'string' },
{
type: 'object',
patternProperties: {
'^.*$': {
anyOf: [
{ type: 'string' },
{ type: 'number' },
],
},
},
},
],
},
confirmText: { type: 'string' },
confirmStyle: {
anyOf: [
{ type: 'string' },
{
type: 'object',
patternProperties: {
'^.*$': {
anyOf: [
{ type: 'string' },
{ type: 'number' },
],
},
},
},
],
},
},
},
disableFunc: { type: 'string' },
Expand Down Expand Up @@ -280,6 +335,8 @@ export default class DTCButton<RecordType extends DripTableRecordTypeBase> exten
);
if (options.popconfirm) {
const popconfirm = options.popconfirm;
const TitleIcon = popconfirm.titleIcon ? this.props.icons?.[popconfirm.titleIcon] : null;
const ContentIcon = popconfirm.contentIcon ? this.props.icons?.[popconfirm.contentIcon] : null;
return (
<DripTableContext.Consumer>
{
Expand All @@ -289,19 +346,22 @@ export default class DTCButton<RecordType extends DripTableRecordTypeBase> exten
overlayInnerStyle={this.parseReactCSS(popconfirm.overlayInnerStyle)}
title={(
<div style={{ fontSize: '14px', fontWeight: '600', lineHeight: '22px' }}>
{ TitleIcon ? <TitleIcon style={this.parseReactCSS(popconfirm.titleIconStyle)} /> : null }
{ finalizeString('pattern', popconfirm.title, this.props.record, this.props.recordIndex, this.props.ext) }
</div>
)}
overlay={(
<div>
<div style={{ fontSize: '14px', fontWeight: '400', lineHeight: '22px', marginTop: '4px' }}>
{ ContentIcon ? <ContentIcon style={this.parseReactCSS(popconfirm.contentIconStyle)} /> : null }
{ finalizeString('pattern', popconfirm.content, this.props.record, this.props.recordIndex, this.props.ext) }
</div>
<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '8px' }}>
{
popconfirm.cancelText
? (
<Button
style={this.parseReactCSS(popconfirm.cancelStyle)}
size="small"
onClick={() => {
this.setState({ showPopconfirm: false });
Expand All @@ -313,7 +373,7 @@ export default class DTCButton<RecordType extends DripTableRecordTypeBase> exten
: null
}
<Button
style={{ marginLeft: '10px' }}
style={{ marginLeft: '10px', ...this.parseReactCSS(popconfirm.confirmStyle) }}
type="primary"
size="small"
shape={options.shape}
Expand Down
2 changes: 1 addition & 1 deletion packages/drip-table/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export interface DripTableProps<
* 图标库
*/
icons?: {
[iconName: string]: React.JSXElementConstructor<React.PropsWithChildren<unknown>>;
[iconName: string]: React.JSXElementConstructor<React.PropsWithChildren<{ style?: React.CSSProperties }>>;
};
/**
* Schema 校验配置项
Expand Down
4 changes: 2 additions & 2 deletions packages/drip-table/src/utils/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const finalizeSchema = <T extends SchemaObject = SchemaObject>(schema: T, option
return schema;
};

const DRIP_TABLE_CSS_SCHEMA: SchemaObject = {
export const DRIP_TABLE_CSS_SCHEMA: SchemaObject = {
type: 'object',
patternProperties: {
'^.*$': {
Expand All @@ -81,7 +81,7 @@ const DRIP_TABLE_CSS_SCHEMA: SchemaObject = {
},
};

const DRIP_TABLE_GENERIC_CSS_SCHEMA: SchemaObject = {
export const DRIP_TABLE_GENERIC_CSS_SCHEMA: SchemaObject = {
anyOf: [
{ type: 'string' },
DRIP_TABLE_CSS_SCHEMA,
Expand Down
Loading