From efae9f05e6c2826b64966e9bca6b2fca720451f7 Mon Sep 17 00:00:00 2001 From: tristan Date: Sun, 29 Sep 2019 17:07:43 +0800 Subject: [PATCH] feat: opposite color --- src/Global.style.js | 7 +++++-- src/components/Color.js | 40 +++++++++++++++++++++++++--------------- src/pages/index.js | 1 + 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Global.style.js b/src/Global.style.js index e7e42df..c3edf70 100644 --- a/src/Global.style.js +++ b/src/Global.style.js @@ -10,7 +10,10 @@ const GlobalStyle = createGlobalStyle` -webkit-text-size-adjust: none; -webkit-tap-highlight-color: rgba(0,0,0,0); color:#ffffeb; - touch-action: manipulation + touch-action: manipulation; + } + span,p,i{ + color:inherit; } html{ -webkit-font-smoothing: antialiased; @@ -19,7 +22,7 @@ const GlobalStyle = createGlobalStyle` } *::-webkit-scrollbar { width: 0px; - background: transparent; /* Optional: just make scrollbar invisible */ + background: transparent; } body{ -webkit-overflow-scrolling: touch; diff --git a/src/components/Color.js b/src/components/Color.js index 3213b27..a390da9 100644 --- a/src/components/Color.js +++ b/src/components/Color.js @@ -1,12 +1,11 @@ import React, { useEffect, useRef } from 'react'; import styled from 'styled-components'; import scrollIntoView from 'scroll-into-view-if-needed'; +import { getCorrectTextColor } from '../utils'; import CirclePercent from './CirclePercent'; -const Wrapper = styled.li.attrs(({ color }) => ({ - style: { borderTopColor: color } -}))` - color: #fff; +const Wrapper = styled.li` + color: ${({ color }) => color}; border-top: 0.4rem solid; display: flex; flex-direction: row; @@ -26,7 +25,6 @@ const Wrapper = styled.li.attrs(({ color }) => ({ &.curr { opacity: 1; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); - text-shadow: 0 0 10px black; } .line1 { display: flex; @@ -63,7 +61,7 @@ const Wrapper = styled.li.attrs(({ color }) => ({ text-transform: uppercase; font-size: 0.6rem; font-weight: bold; - color: #fff; + color: ${({ color }) => color}; .hex { font-size: 0.6rem; } @@ -74,15 +72,14 @@ const Wrapper = styled.li.attrs(({ color }) => ({ display: flex; flex-direction: column; .line { - /* background-image: linear-gradient(180deg, #ddd 45%, #fff 40%); */ width: 2px; height: 6rem; margin: 0 1px; &.r { background-image: linear-gradient( 180deg, - rgba(255, 255, 255) 0%, - rgba(255, 255, 255) ${({ rgb }) => 100 * (rgb[0] / 255)}%, + ${({ color }) => color} 0%, + ${({ color }) => color} ${({ rgb }) => 100 * (rgb[0] / 255)}%, rgba(255, 255, 255, 0.3) ${({ rgb }) => 100 * (rgb[0] / 255)}%, rgba(255, 255, 255, 0.3) 100% ); @@ -90,8 +87,8 @@ const Wrapper = styled.li.attrs(({ color }) => ({ &.g { background-image: linear-gradient( 180deg, - rgba(255, 255, 255) 0%, - rgba(255, 255, 255) ${({ rgb }) => 100 * (rgb[1] / 255)}%, + ${({ color }) => color} 0%, + ${({ color }) => color} ${({ rgb }) => 100 * (rgb[1] / 255)}%, rgba(255, 255, 255, 0.3) ${({ rgb }) => 100 * (rgb[1] / 255)}%, rgba(255, 255, 255, 0.3) 100% ); @@ -99,8 +96,8 @@ const Wrapper = styled.li.attrs(({ color }) => ({ &.b { background-image: linear-gradient( 180deg, - rgba(255, 255, 255) 0%, - rgba(255, 255, 255) ${({ rgb }) => 100 * (rgb[2] / 255)}%, + ${({ color }) => color} 0%, + ${({ color }) => color} ${({ rgb }) => 100 * (rgb[2] / 255)}%, rgba(255, 255, 255, 0.3) ${({ rgb }) => 100 * (rgb[2] / 255)}%, rgba(255, 255, 255, 0.3) 100% ); @@ -110,10 +107,22 @@ const Wrapper = styled.li.attrs(({ color }) => ({ } `; -const Color = ({ setCurrColor, seq = 1, isCurr, hex, name, pinyin, CMYK, RGB, intro }) => { +const Color = ({ + setCurrColor, + seq = 1, + isCurr, + hex, + name, + pinyin, + CMYK, + RGB, + intro, + currColorRGB +}) => { const [r, g, b] = RGB; const [c, m, y, k] = CMYK; const colorEle = useRef(null); + const oppoColor = getCorrectTextColor(currColorRGB); useEffect(() => { if (isCurr) { scrollIntoView(colorEle.current, { @@ -129,8 +138,9 @@ const Color = ({ setCurrColor, seq = 1, isCurr, hex, name, pinyin, CMYK, RGB, in rgb={RGB} className={isCurr && 'curr'} onClick={setCurrColor.bind(null, name)} - color={hex} + color={oppoColor} title={intro ? intro : null} + style={{ borderTopColor: hex }} >
diff --git a/src/pages/index.js b/src/pages/index.js index 4c9b7be..0c8f650 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -69,6 +69,7 @@ const Index = () => { return (