Skip to content

Instantly share code, notes, and snippets.

@haikyuu
Last active December 7, 2016 16:13
Show Gist options
  • Save haikyuu/25be4fc0e8126292d3bede9d03995dae to your computer and use it in GitHub Desktop.
Save haikyuu/25be4fc0e8126292d3bede9d03995dae to your computer and use it in GitHub Desktop.
styled-components debugger. Credits to @thekitze
import {css} from 'styled-components'
var colorIndex = -1
const getRandomColor = ()=> {
var letters = '0123456789ABCDEF';
//pretty colors
const colors = [ '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B',]
colorIndex++;
return colors[colorIndex % colors.length];
}
export const debug = (text, color = getRandomColor())=>{
return css`
border: 4px solid ${color};
${text && `position: relative;`}
${text && `&:after{
content: '${text}';
background-color: papayawhip;
color: steelblue;
padding: 2px 10px;
text-align: center;
position: absolute;
top: 0;
left: 0;
}`}
`
}
const Box = styled.div`
width: 70%;
height: 24vw;
background: white;
border-radius: 1.2vh;
position: relative;
${debug('BOX')}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment