Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/javascript/components/settings-tasks-form/icons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { carbonizeIcon } from '../../menu/icon';
const Icon = ({
text, icon, color, size,
}) => {
const IconElement = carbonizeIcon(icon, size);
const IconElement = carbonizeIcon(icon, { size });
return (
<div id="icon">
<IconElement aria-label={text} className="my-custom-class" color={color} />
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/components/toolbar/MenuIcon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable react/destructuring-assignment */
import React from 'react';
import PropTypes from 'prop-types';
import { carbonizeIcon } from '../../menu/icon';

export const MenuIcon = (props) => (
<div>
{ props.icon && <i className={props.icon} style={{ color: props.color }} /> }
{ props.icon && carbonizeIcon(props.icon, { color: props.color }) }
{' '}
<span>{ props.text }</span>
</div>
Expand Down
6 changes: 5 additions & 1 deletion app/javascript/components/toolbar/ToolbarButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import PropTypes from 'prop-types';

import { adjustColor, isEnabled } from './utility';
import CountContext from './ToolbarContext';
import { carbonizeIcon } from '../../menu/icon';

const classNames = require('classnames');

const ButtonIcon = ({
img_url: imgUrl, icon, color, enabled,
}) => {
if (icon) {
return <i className={icon} style={{ color: adjustColor(color, enabled) }} />;
const options = {
color: adjustColor(color, enabled),
};
return carbonizeIcon(icon, options);
}

if (imgUrl && !icon) {
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/components/toolbar/ToolbarList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MenuIcon } from './MenuIcon';
import { isEnabled } from './utility';
import { ToolbarClick } from './ToolbarClick';
import CountContext from './ToolbarContext';
import { carbonizeIcon } from '../../menu/icon';

export const ToolbarList = (props) => {
const count = useContext(CountContext);
Expand Down Expand Up @@ -58,7 +59,7 @@ export const ToolbarList = (props) => {
onClose={closeFunc}
renderIcon={() => (
<div className="toolbar-overflow">
{ props.icon && <i className={props.icon} style={{ color: props.color }} /> }
{ props.icon && carbonizeIcon(props.icon, { color: props.color }) }
<ChevronDown20 />
{' '}
<span>{ props.text ? props.text : (props.title && props.title)}</span>
Expand Down
13 changes: 10 additions & 3 deletions app/javascript/menu/icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import React from 'react';
import PropTypes from 'prop-types';
import * as icons from '@carbon/icons-react';

export const carbonizeIcon = (classname, size = 20) => {
export const carbonizeIcon = (classname, options = undefined) => {
const size = (options && options.size) || 20; // Default size is 16px
console.log(classname);
console.log(size);

if (!classname) {
return null;
}

if (!classname.startsWith('carbon--')) {
return props => <i className={classname} {...props} />;
if (options && options.color) {
return <i className={classname} style={{ color: options.color }} />;
}
return <i className={classname} />;
}

const name = classname.replace(/^carbon--/, '');
Expand All @@ -17,7 +24,7 @@ export const carbonizeIcon = (classname, size = 20) => {
};

const MiqIcon = ({ icon, size }) => {
const IconElement = carbonizeIcon(icon, size);
const IconElement = carbonizeIcon(icon, { size });
return <IconElement style={{ marginBottom: '-4px' }} />;
};

Expand Down