diff --git a/.eslintrc.js b/.eslintrc.js index 76b7482a9..1f8aa4e0f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,6 +16,8 @@ module.exports = { }, rules: { 'no-shadow': 0, + 'react/button-has-type': 0, + 'jsx-a11y/click-events-have-key-events': 0, camelcase: 0, '@typescript-eslint/ban-ts-ignore': 0, 'arrow-body-style': 0, diff --git a/.umirc.js b/.umirc.js index 15b33e437..69acfb89f 100644 --- a/.umirc.js +++ b/.umirc.js @@ -20,8 +20,7 @@ export default { // 'packages/graphin-graphscope/docs/', /** local develop */ - // 'packages/graphin/docs/case/graph-database', - // 'packages/graphin/docs/index.md', + // 'packages/graphin-components/src/VisSettingPanel', ], }, alias: { @@ -53,10 +52,10 @@ export default { title: 'v1.6.4', path: 'https://antv.vision/graphin-1.x-site/', }, - { - title: 'GitHub', - path: 'https://github.com/antvis/Graphin', - }, + // { + // title: 'GitHub', + // path: 'https://github.com/antvis/Graphin', + // }, ], analytics: isProduction ? { ga: 'UA-148148901-8' } : false, diff --git a/packages/graphin-components/src/VisSettingPanel/demos/AntdPanel.tsx b/packages/graphin-components/src/VisSettingPanel/demos/AntdPanel.tsx index a9fb5a0f4..d33c7067c 100644 --- a/packages/graphin-components/src/VisSettingPanel/demos/AntdPanel.tsx +++ b/packages/graphin-components/src/VisSettingPanel/demos/AntdPanel.tsx @@ -1,6 +1,7 @@ +/* eslint-disable no-undef */ import React from 'react'; -import { Collapse, Card, Tabs } from 'antd'; -import { NodeStyle } from '@antv/graphin'; +import { Collapse, Card, Tabs, Switch } from 'antd'; +import { GraphinContext } from '@antv/graphin'; import LabelSetting from './components/LabelSetting'; import IconSetting from './components/IconSetting'; import KeyShapeSetting from './components/KeyShapeSetting'; @@ -9,26 +10,60 @@ import HaloSetting from './components/HaloSetting'; const { Panel } = Collapse; const { TabPane } = Tabs; -interface AntdPanelProps { - nodeStyleSchema: NodeStyle; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - handleNodeStyleChange: (value: any) => void; -} +const handleChangeTheme = checked => { + console.log(checked); + // dom 是一个 style 样式文件的链接 + // eslint-disable-next-line no-undef + const dom = window.document.getElementById('theme-style') as HTMLLinkElement; + const cssUrl = checked + ? 'https://gw.alipayobjects.com/os/lib/antd/4.6.6/dist/antd.css' + : 'https://gw.alipayobjects.com/os/lib/antd/4.6.6/dist/antd.dark.css'; -const AntdPanel: React.FunctionComponent = (props) => { - const { nodeStyleSchema, handleNodeStyleChange } = props; + if (dom) { + dom.href = cssUrl; + } else { + // 创建一个 stylesheet 文件链接,动态 append 到 body 中 + // eslint-disable-next-line no-undef + const style = document.createElement('link'); + style.type = 'text/css'; + style.rel = 'stylesheet'; + style.id = 'theme-style'; + style.href = cssUrl; + if (document.body.append) { + document.body.append(style); + } else { + document.body.appendChild(style); + } + } +}; +// interface AntdPanelProps { +// nodeStyleSchema: NodeStyle; +// // eslint-disable-next-line @typescript-eslint/no-explicit-any +// handleNodeStyleChange: (value: any) => void; +// } + +const AntdPanel = () => { + const graphin = React.useContext(GraphinContext); + + const { nodeStyleSchema, handleNodeStyleChange } = graphin.visSettingPanel; const { label, icon, keyshape } = nodeStyleSchema; - const handleChange = (shema) => { + const handleChange = shema => { console.log('shema', shema); handleNodeStyleChange(shema); }; return (
- + } + > - + diff --git a/packages/graphin-components/src/VisSettingPanel/demos/components/ColorPicker.tsx b/packages/graphin-components/src/VisSettingPanel/demos/components/ColorPicker.tsx index 2d902d16b..f81df7abc 100644 --- a/packages/graphin-components/src/VisSettingPanel/demos/components/ColorPicker.tsx +++ b/packages/graphin-components/src/VisSettingPanel/demos/components/ColorPicker.tsx @@ -1,6 +1,6 @@ +/* eslint-disable jsx-a11y/no-static-element-interactions */ import React from 'react'; -import { Button } from 'antd'; -import { TwitterPicker } from 'react-color'; +import { ChromePicker } from 'react-color'; interface ColorPickerProps { onChange: (color: string) => void; @@ -11,6 +11,21 @@ interface ColorPickerState { visible: boolean; value: string; } +const styles = { + color: { + width: '36px', + height: '14px', + borderRadius: '2px', + padding: '5px', + border: '5px solid #ddd', + display: 'inline-block', + textAlign: 'top', + }, + popover: { + position: 'absolute', + zIndex: '2', + }, +}; const ColorPicker = (props: ColorPickerProps) => { const { onChange, color } = props; @@ -24,7 +39,7 @@ const ColorPicker = (props: ColorPickerProps) => { onChange(value.hex); setState({ ...state, - visible: false, + // visible: false, value: value.hex, }); }; @@ -34,14 +49,22 @@ const ColorPicker = (props: ColorPickerProps) => { visible: !state.visible, }); }; + const handleClose = () => { + setState({ + ...state, + visible: false, + }); + }; - const { visible, colors, value } = state; + const { visible, value } = state; return (
-