From 52b3ebdf13af64816371d2137dd1bb695def3093 Mon Sep 17 00:00:00 2001 From: Bill Sheikh Date: Fri, 10 Mar 2017 01:56:11 -0500 Subject: [PATCH] Add ability to copy color on palette click (#5247) --- docs/spec/colors.md | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/spec/colors.md b/docs/spec/colors.md index d59a01095e..ed76b2f02b 100644 --- a/docs/spec/colors.md +++ b/docs/spec/colors.md @@ -26,6 +26,8 @@ Ant Design 的色板由 8 种基本色彩组成,每种基本色(第 6 格) `````__react +import CopyToClipboard from 'react-copy-to-clipboard'; +import { message } from 'antd'; const rgbToHex = (rgbString) => { const hexChars = '0123456789ABCDEF'; const rgb = rgbString.match(/\d+/g); @@ -48,25 +50,31 @@ const Palette = React.createClass({ }); this.setState({ hexColors }); }, + onCopied() { + message.success('Copied.'); + }, render() { this.colorNodes = this.colorNodes || {}; const { name, description, color } = this.props.color; const { hexColors } = this.state; const colors = []; for (let i = 1; i <= 10; i++) { + const colorText = `${name}-${i}`; colors.push( -
{ this.colorNodes[`${name}-${i}`] = node; } } - className={`main-color-item palatte-${name}-${i}`} - style={{ - color: i > 5 ? '#fff' : 'unset', - fontWeight: i === 6 ? 'bold' : 'normal', - }} - > - {name}-{i} - {hexColors ? {hexColors[`${name}-${i}`]} : null} -
+ +
{ this.colorNodes[`${name}-${i}`] = node; } } + className={`main-color-item palatte-${name}-${i}`} + style={{ + color: i > 5 ? '#fff' : 'unset', + fontWeight: i === 6 ? 'bold' : 'normal', + }} + > + {colorText} + {hexColors ? {hexColors[`${name}-${i}`]} : null} +
+
); } return (