-
Notifications
You must be signed in to change notification settings - Fork 16
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
LegendCategories: support for custom markers #451
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { getPalette } from '../../utils/palette'; | |
import PropTypes from 'prop-types'; | ||
|
||
function LegendCategories({ legend }) { | ||
const { labels = [], colors = [], isStrokeColor = false } = legend; | ||
const { labels = [], colors = [], isStrokeColor = false, customMarkers } = legend; | ||
|
||
const palette = getPalette(colors, labels.length); | ||
|
||
|
@@ -14,6 +14,9 @@ function LegendCategories({ legend }) { | |
isMax={false} | ||
label={label} | ||
color={palette[idx]} | ||
icon={ | ||
customMarkers && Array.isArray(customMarkers) ? customMarkers[idx] : customMarkers | ||
} | ||
isStrokeColor={isStrokeColor} | ||
/> | ||
)); | ||
|
@@ -42,6 +45,10 @@ LegendCategories.propTypes = { | |
legend: PropTypes.shape({ | ||
labels: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
colors: PropTypes.oneOfType([PropTypes.arrayOf(ColorType), PropTypes.string]), | ||
customMarkers: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.string | ||
]), | ||
isStrokeColor: PropTypes.bool | ||
}).isRequired | ||
}; | ||
|
@@ -56,14 +63,11 @@ const useStyles = makeStyles((theme) => ({ | |
'& $circle': {} | ||
} | ||
}, | ||
circle: { | ||
marker: { | ||
whiteSpace: 'nowrap', | ||
display: 'block', | ||
width: '12px', | ||
height: '12px', | ||
borderRadius: '50%', | ||
position: 'relative', | ||
border: '2px solid transparent', | ||
|
||
'&::after': { | ||
position: 'absolute', | ||
display: ({ isMax }) => (isMax ? 'block' : 'none'), | ||
|
@@ -76,6 +80,16 @@ const useStyles = makeStyles((theme) => ({ | |
boxSizing: 'content-box' | ||
} | ||
}, | ||
markerCircle: { | ||
width: '12px', | ||
height: '12px', | ||
border: '2px solid transparent', | ||
borderRadius: '50%' | ||
}, | ||
markerIcon: { | ||
width: '16px', | ||
height: '16px' | ||
}, | ||
flexParent: { | ||
display: 'flex', | ||
alignItems: 'center' | ||
|
@@ -94,7 +108,7 @@ const useStyles = makeStyles((theme) => ({ | |
} | ||
})); | ||
|
||
function Row({ label, isMax, isStrokeColor, color = '#000' }) { | ||
function Row({ label, isMax, isStrokeColor, color = '#000', icon }) { | ||
const classes = useStyles({ isMax }); | ||
|
||
const [showTooltip, setShowTooltip] = useState(false); | ||
|
@@ -121,8 +135,25 @@ function Row({ label, isMax, isStrokeColor, color = '#000' }) { | |
<Box | ||
mr={1.5} | ||
component='span' | ||
className={classes.circle} | ||
style={isStrokeColor ? { borderColor: color } : { backgroundColor: color }} | ||
className={[ | ||
classes.marker, | ||
icon ? classes.markerIcon : classes.markerCircle | ||
].join(' ')} | ||
style={ | ||
icon | ||
? { | ||
backgroundColor: color, | ||
maskRepeat: 'no-repeat', | ||
maskSize: 'cover', | ||
maskImage: `url(${icon})`, | ||
WebkitMaskRepeat: 'no-repeat', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really required? MaterialUI is supposed to detect & add vendor prefixes (https://v4.mui.com/styles/advanced/#css-prefixes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about mui. This is not MUI, btw, this is generic react There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VictorVelarde It's some other magic mechanism, which understands Firefox difference and ... if we don't add In other words, our "framework" understands which props are supported by which browser and emits only those into DOM.Too many frameworks for me |
||
WebkitMaskSize: 'cover', | ||
WebkitMaskImage: `url(${icon})` | ||
} | ||
: isStrokeColor | ||
? { borderColor: color } | ||
: { backgroundColor: color } | ||
} | ||
/> | ||
</Tooltip> | ||
<Typography ref={labelRef} variant='overline' className={classes.longTruncate}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VictorVelarde
So update on story:
makeStyles
like above!style={{...}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I didn't notice those were inline styles and they were excluded. This way is better, thx!