Skip to content

Commit

Permalink
fix: put Single Stat default styles into stylesheet to prevent font f…
Browse files Browse the repository at this point in the history
…lashing (#822)
  • Loading branch information
TCL735 authored Oct 11, 2022
1 parent a88b2fb commit 5018caa
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 29 deletions.
2 changes: 1 addition & 1 deletion giraffe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ TableGraphLayerConfig uses the `fluxResponse` property from `config` as the data
</div>
</pre>

- **style**: _Object. Optional. Recommendation: do not include._ An object containing the key-value pairs used for inline styling `.giraffe-layer-single-stat` by setting its [style property](https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style). If used, please be aware of existing default styles that may need to be overridden. `backgroundColor` cannot be overridden and is controlled by the **backgroundColor** option (see above). See the `SINGLE_STAT_DEFAULT_STYLE` [here](./src/constants/singleStatStyles.ts).
- **style**: _Object. Optional. Recommendation: do not include._ An object containing the key-value pairs used for inline styling `.giraffe-layer-single-stat` by setting its [style property](https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style). If used, please be aware of existing default styles that may need to be overridden. `backgroundColor` cannot be overridden and is controlled by the **backgroundColor** option (see above).

- **resizerStyle**: _Object. Optional. Recommendation: do not include._ An object containing the key-value pairs used for inline styling `.giraffe-single-stat--resizer` by setting its [style property](https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style). If used, please be aware of existing default styles that may need to be overridden. See the `SINGLE_STAT_RESIZER_DEFAULT_STYLE` [here](./src/constants/singleStatStyles.ts).

Expand Down
2 changes: 1 addition & 1 deletion giraffe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/giraffe",
"version": "2.37.1",
"version": "2.38.0",
"main": "dist/index.js",
"module": "dist/index.js",
"license": "MIT",
Expand Down
60 changes: 60 additions & 0 deletions giraffe/src/components/SingleStat/SingleStatLayer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@import '../../style/variables.scss';

@font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 300;
src: url('../../fonts/ProximaNova-Light.woff2') format('woff2');
font-display: block;
}
@font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 400;
src: url('../../fonts/ProximaNova-Regular.woff2') format('woff2');
font-display: block;
}
@font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 500;
src: url('../../fonts/ProximaNova-Medium.woff2') format('woff2');
font-display: block;
}
@font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 700;
src: url('../../fonts/ProximaNova-Bold.woff2') format('woff2');
font-display: block;
}
@font-face {
font-family: 'Proxima Nova';
font-style: normal;
font-weight: 900;
src: url('../../fonts/ProximaNova-Black.woff2') format('woff2');
font-display: block;
}

.giraffe-layer-single-stat {
align-items: center;
border-radius: 4px;
bottom: 0;
color: $c-laser;
cursor: text;
display: flex;
font-family: 'Proxima Nova', Helvetica, Arial, Tahoma, Verdana, sans-serif;
height: 100%;
justify-content: center;
left: 0;
overflow: hidden;
padding: 8px;
position: absolute;
right: 0;
top: 0;
width: 100%;
-moz-user-select: text;
-ms-user-select: text;
-webkit-user-select: text;
user-select: text;
}
7 changes: 7 additions & 0 deletions giraffe/src/components/SingleStat/SingleStatLayer.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is automatically generated.
// Please do not change this file!
interface CssExports {
'giraffe-layer-single-stat': string;
}
export const cssExports: CssExports;
export default cssExports;
15 changes: 12 additions & 3 deletions giraffe/src/components/SingleStat/SingleStatLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {FunctionComponent} from 'react'
import classnames from 'classnames'
import {
SINGLE_STAT_DEFAULT_STYLE,
SINGLE_STAT_DEFAULT_TEST_ID,
SINGLE_STAT_RESIZER_DEFAULT_STYLE,
SINGLE_STAT_SVG_DEFAULT_ATTRIBUTES,
Expand All @@ -10,6 +10,10 @@ import {
import {SingleStatLayerConfig} from '../../types'
import {formatStatValue} from '../../utils/formatStatValue'

import styles from './SingleStatLayer.scss'

import {styleReducer} from '../../utils/styleReducer'

interface Props {
stat: number
config: SingleStatLayerConfig
Expand All @@ -36,6 +40,12 @@ export const SingleStatLayer: FunctionComponent<Props> = props => {
textOpacity = 1,
} = config

const singleStatLayerClasses = styleReducer(
styles,
'giraffe-layer giraffe-layer-single-stat',
classnames('giraffe-layer-single-stat')
)

const formattedValue = formatStatValue(stat, {decimalPlaces, prefix, suffix})

let viewBox = getDefaultViewBox(formattedValue)
Expand All @@ -49,10 +59,9 @@ export const SingleStatLayer: FunctionComponent<Props> = props => {

return (
<div
className="giraffe-layer giraffe-layer-single-stat"
className={singleStatLayerClasses}
data-testid={testID}
style={{
...SINGLE_STAT_DEFAULT_STYLE,
...style,
backgroundColor: `${backgroundColor}`,
}}
Expand Down
Binary file added giraffe/src/fonts/ProximaNova-Black.woff2
Binary file not shown.
Binary file added giraffe/src/fonts/ProximaNova-Bold.woff2
Binary file not shown.
Binary file added giraffe/src/fonts/ProximaNova-Light.woff2
Binary file not shown.
Binary file added giraffe/src/fonts/ProximaNova-Medium.woff2
Binary file not shown.
Binary file added giraffe/src/fonts/ProximaNova-Regular.woff2
Binary file not shown.
23 changes: 0 additions & 23 deletions giraffe/src/style/singleStatStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ export const LASER = '#00C9FF'

export const SINGLE_STAT_DEFAULT_TEST_ID = 'giraffe-layer-single-stat'

export const SINGLE_STAT_DEFAULT_STYLE: CSSProperties = {
alignItems: 'center',
borderRadius: '4px',
bottom: 0,
color: LASER,
cursor: 'text',
display: 'flex',
fontFamily: '"Proxima Nova", Helvetica, Arial, Tahoma, Verdana, sans-serif',
height: '100%',
justifyContent: 'center',
left: 0,
MozUserSelect: 'text',
msUserSelect: 'text',
overflow: 'hidden',
padding: '8px',
position: 'absolute',
right: 0,
top: 0,
userSelect: 'text',
WebkitUserSelect: 'text',
width: '100%',
}

export const SINGLE_STAT_RESIZER_DEFAULT_STYLE: CSSProperties = {
overflow: 'hidden',
width: '100%',
Expand Down
1 change: 1 addition & 0 deletions giraffe/src/style/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ $c-amethyst: #8e1fc3;
$c-dreamsicle: #ff8564;
$c-emerald: #006f49;
$c-fire: #dc4e58;
$c-laser: #00c9ff;
$c-ocean: #066fc5;
$c-pineapple: #ffb94a;
$c-pool: #00a3ff;
Expand Down
2 changes: 1 addition & 1 deletion stories/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@influxdata/giraffe-stories",
"version": "2.37.1",
"version": "2.38.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
21 changes: 21 additions & 0 deletions stories/src/singleStat.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ storiesOf('Single Stat', module)
viewBox: stat =>
`${viewBoxX} ${viewBoxY} ${stat.length * viewBoxWidth} 100`,
},
svgTextStyle: {
fontSize: '100',
fontWeight: 'lighter',
dominantBaseline: 'middle',
textAnchor: 'middle',
letterSpacing: '-0.05em',
},
},
],
}
Expand Down Expand Up @@ -133,6 +140,13 @@ storiesOf('Single Stat', module)
viewBox: stat =>
`${viewBoxX} ${viewBoxY} ${stat.length * viewBoxWidth} 100`,
},
svgTextStyle: {
fontSize: '100',
fontWeight: 'lighter',
dominantBaseline: 'middle',
textAnchor: 'middle',
letterSpacing: '-0.05em',
},
},
],
}
Expand Down Expand Up @@ -249,6 +263,13 @@ storiesOf('Single Stat', module)
`${viewBoxX} ${viewBoxY} ${stat.length * viewBoxWidth} 100`,
},
svgStyle: SINGLE_STAT_SVG_NO_USER_SELECT,
svgTextStyle: {
fontSize: '100',
fontWeight: 'lighter',
dominantBaseline: 'middle',
textAnchor: 'middle',
letterSpacing: '-0.05em',
},
})
}

Expand Down

0 comments on commit 5018caa

Please sign in to comment.