From a9c609be556baa94a6ac7a22fbdc10112f63ab63 Mon Sep 17 00:00:00 2001 From: Kevin Schiffer Date: Fri, 2 Feb 2024 12:25:50 +0900 Subject: [PATCH] console: Introduce replacement icons as part of icon component --- pkg/webui/components/icon/icon.styl | 17 +++++++++++++++-- pkg/webui/components/icon/index.js | 14 ++++++++++++++ .../index.js => icon/replacements/plus-icon.js} | 14 ++++++++++---- .../index.js => icon/replacements/star-icon.js} | 14 ++++++++++---- pkg/webui/components/panel/index.js | 3 --- pkg/webui/components/panel/panel.styl | 10 +--------- pkg/webui/components/panel/story.js | 4 +--- 7 files changed, 51 insertions(+), 25 deletions(-) rename pkg/webui/components/{plus-icon/index.js => icon/replacements/plus-icon.js} (87%) rename pkg/webui/components/{star-icon/index.js => icon/replacements/star-icon.js} (89%) diff --git a/pkg/webui/components/icon/icon.styl b/pkg/webui/components/icon/icon.styl index 325492d7b9..7337db172e 100644 --- a/pkg/webui/components/icon/icon.styl +++ b/pkg/webui/components/icon/icon.styl @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -.icon +span.icon material-icon() &.small @@ -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 @@ -32,6 +45,6 @@ .text-padded &-right margin-right: $cs.xxs - + &-left margin-left: $cs.xxs diff --git a/pkg/webui/components/icon/index.js b/pkg/webui/components/icon/index.js index 33709c9493..14c4f6e30c 100644 --- a/pkg/webui/components/icon/index.js +++ b/pkg/webui/components/icon/index.js @@ -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. @@ -71,6 +74,11 @@ const hardcoded = { valid: 'check_circle', } +const replaced = { + star: StarIcon, + plus: PlusIcon, +} + const Icon = forwardRef((props, ref) => { const { icon, @@ -93,6 +101,12 @@ const Icon = forwardRef((props, ref) => { [style.textPaddedRight]: textPaddedRight, }) + if (replaced[icon]) { + const ReplacedIcon = replaced[icon] + + return + } + return ( {hardcoded[icon] || icon} diff --git a/pkg/webui/components/plus-icon/index.js b/pkg/webui/components/icon/replacements/plus-icon.js similarity index 87% rename from pkg/webui/components/plus-icon/index.js rename to pkg/webui/components/icon/replacements/plus-icon.js index f25a1947bc..4e506105e8 100644 --- a/pkg/webui/components/plus-icon/index.js +++ b/pkg/webui/components/icon/replacements/plus-icon.js @@ -1,4 +1,4 @@ -// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2024 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,8 +16,14 @@ import React from 'react' import PropTypes from '@ttn-lw/lib/prop-types' -const PlusIcon = ({ className }) => ( - +const PlusIcon = React.forwardRef(({ className }, ref) => ( + ( /> -) +)) PlusIcon.propTypes = { className: PropTypes.string, diff --git a/pkg/webui/components/star-icon/index.js b/pkg/webui/components/icon/replacements/star-icon.js similarity index 89% rename from pkg/webui/components/star-icon/index.js rename to pkg/webui/components/icon/replacements/star-icon.js index 593fd8cdb0..7da1d2f9d3 100644 --- a/pkg/webui/components/star-icon/index.js +++ b/pkg/webui/components/icon/replacements/star-icon.js @@ -1,4 +1,4 @@ -// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2024 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,8 +16,14 @@ import React from 'react' import PropTypes from '@ttn-lw/lib/prop-types' -const StarIcon = ({ className }) => ( - +const StarIcon = React.forwardRef(({ className }, ref) => ( + ( /> -) +)) StarIcon.propTypes = { className: PropTypes.string, diff --git a/pkg/webui/components/panel/index.js b/pkg/webui/components/panel/index.js index 93c62e3038..59308151d3 100644 --- a/pkg/webui/components/panel/index.js +++ b/pkg/webui/components/panel/index.js @@ -30,7 +30,6 @@ const Panel = ({ children, title, icon, - svgIcon, toggleOptions, activeToggle, onToggleClick, @@ -44,7 +43,6 @@ const Panel = ({
{icon && } - {svgIcon} {messageDecorators}
@@ -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({})), } diff --git a/pkg/webui/components/panel/panel.styl b/pkg/webui/components/panel/panel.styl index c17ba0176d..bc4a1b0154 100644 --- a/pkg/webui/components/panel/panel.styl +++ b/pkg/webui/components/panel/panel.styl @@ -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 @@ -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 diff --git a/pkg/webui/components/panel/story.js b/pkg/webui/components/panel/story.js index d7091e02da..48769dc8b1 100644 --- a/pkg/webui/components/panel/story.js +++ b/pkg/webui/components/panel/story.js @@ -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 '.' @@ -73,7 +71,7 @@ export const WithToggle = () => { return (
- } toggleOptions={options} /> +
) }