Skip to content

Commit

Permalink
console: Introduce replacement icons as part of icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiffer committed Feb 2, 2024
1 parent 3a1f579 commit 36356bc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 115 deletions.
17 changes: 15 additions & 2 deletions pkg/webui/components/icon/icon.styl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

.icon
span.icon
material-icon()

&.small
Expand All @@ -21,6 +21,19 @@
&.large
font-size: 2rem

svg.icon
height: 1.5rem
width: 1.5rem

&.small
height: 1rem
width: 1rem

&.large
height: 2rem
width: 2rem

.icon
&.nudgeUp
position: relative
top: -1px
Expand All @@ -32,6 +45,6 @@
.text-padded
&-right
margin-right: $cs.xxs

&-left
margin-left: $cs.xxs
14 changes: 14 additions & 0 deletions pkg/webui/components/icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import React, { forwardRef } from 'react'
import classnames from 'classnames'
import PropTypes from 'prop-types'

import StarIcon from './replacements/star-icon'
import PlusIcon from './replacements/plus-icon'

import style from './icon.styl'

// A map of hardcoded names to their corresponding icons.
Expand Down Expand Up @@ -71,6 +74,11 @@ const hardcoded = {
valid: 'check_circle',
}

const replaced = {
star: StarIcon,
plus: PlusIcon,
}

const Icon = forwardRef((props, ref) => {
const {
icon,
Expand All @@ -93,6 +101,12 @@ const Icon = forwardRef((props, ref) => {
[style.textPaddedRight]: textPaddedRight,
})

if (replaced[icon]) {
const ReplacedIcon = replaced[icon]

return <ReplacedIcon className={classname} ref={ref} {...rest} />
}

return (
<span className={classname} ref={ref} {...rest}>
{hardcoded[icon] || icon}
Expand Down
3 changes: 0 additions & 3 deletions pkg/webui/components/panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const Panel = ({
children,
title,
icon,
svgIcon,
toggleOptions,
activeToggle,
onToggleClick,
Expand All @@ -44,7 +43,6 @@ const Panel = ({
<div className="d-flex j-between al-center mb-cs-m">
<div className="d-flex gap-cs-xs al-center">
{icon && <Icon icon={icon} className={styles.panelHeaderIcon} />}
{svgIcon}
<Message content={title} className={styles.panelHeaderTitle} />
{messageDecorators}
</div>
Expand All @@ -71,7 +69,6 @@ Panel.propTypes = {
messageDecorators: PropTypes.node,
onToggleClick: PropTypes.func,
path: PropTypes.string.isRequired,
svgIcon: PropTypes.node,
title: PropTypes.message.isRequired,
toggleOptions: PropTypes.arrayOf(PropTypes.shape({})),
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/webui/components/panel/panel.styl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
font-size: $fsv2.l
line-height: 1

svg
width: 21px
height: 21px
background-color: var(--c-bg-brand-extralight)
padding: $cs.xs
border-radius: $br.l
color: var(--c-bg-brand-normal)

a.button
font-weight: $fwv2.semibold
text-decoration: none transparent
Expand All @@ -52,7 +44,7 @@
margin-bottom: $cs.l
height: 0px

span.panel-header-icon
.panel-header-icon
font-size: 1.5rem
background-color: var(--c-bg-brand-extralight)
padding: $cs.xs
Expand Down
4 changes: 1 addition & 3 deletions pkg/webui/components/panel/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import React from 'react'

import loginVisual from '@assets/img/layout/bg/login-visual.jpg'

import StarIcon from '@ttn-lw/components/star-icon'

import NewsItem from '../news-panel/news-item'

import Panel from '.'
Expand Down Expand Up @@ -73,7 +71,7 @@ export const WithToggle = () => {

return (
<div style={{ width: '32.5rem' }}>
<Example title="Your top entities" svgIcon={<StarIcon />} toggleOptions={options} />
<Example title="Your top entities" icon="star" toggleOptions={options} />
</div>
)
}
49 changes: 0 additions & 49 deletions pkg/webui/components/plus-icon/index.js

This file was deleted.

49 changes: 0 additions & 49 deletions pkg/webui/components/star-icon/index.js

This file was deleted.

0 comments on commit 36356bc

Please sign in to comment.