Skip to content

Commit

Permalink
Add 'theme' prop for SidebarMenuItem to support css variables (#192)
Browse files Browse the repository at this point in the history
* Add 'theme' prop for SidebarMenuItem  to support css variables

* bumped version

Co-authored-by: Irina Borozan <[email protected]>
  • Loading branch information
cipick and aniri authored May 17, 2020
1 parent 1f31020 commit 88f8b38
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code4ro/taskforce-fe-components",
"version": "1.0.26",
"version": "1.0.27",
"private": false,
"dependencies": {
"bulma": "^0.8.0",
Expand Down
17 changes: 14 additions & 3 deletions src/components/sidebar-menu-item/sidebar-menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import PropTypes from "prop-types";
import "./sidebar-menu-item.scss";
import classNames from "classnames";
import { onEnterOrSpace } from "../../a11y";
import { useCssVars } from "../../hooks/useCssVars";

export const SidebarMenuItem = ({ active, isTitle, children, onClick }) => {
export const SidebarMenuItem = ({
active,
isTitle,
children,
onClick,
theme
}) => {
const style = useCssVars(theme);
const onClickCb = () => {
if (onClick) {
onClick();
Expand All @@ -21,6 +29,7 @@ export const SidebarMenuItem = ({ active, isTitle, children, onClick }) => {
})}
onClick={onClickCb}
onKeyPress={onEnterOrSpace(onClickCb)}
style={style}
>
{children}
</li>
Expand All @@ -31,10 +40,12 @@ SidebarMenuItem.propTypes = {
active: PropTypes.bool,
isTitle: PropTypes.bool,
onClick: PropTypes.func,
children: PropTypes.node.isRequired
children: PropTypes.node.isRequired,
theme: PropTypes.object
};

SidebarMenuItem.SidebarMenuItem = {
active: false,
isTitle: false
isTitle: false,
theme: false
};
9 changes: 6 additions & 3 deletions src/components/sidebar-menu-item/sidebar-menu-item.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
.__sidebar-menu-item {
--highlightColor: #b6cadb;
--backgroundColor: #f5f5f5;

list-style-type: none;
border-left: 40px solid #b6cadb;
background: #f5f5f5;
border-left: 40px solid var(--highlightColor);
background: var(--backgroundColor);
margin: 5px 0;
padding: 5px 10px;
}

.__sidebar-menu-item:hover,
.__sidebar-menu-item.active {
background: #b6cadb;
background: var(--highlightColor);
cursor: pointer;
}

Expand Down
29 changes: 29 additions & 0 deletions src/components/sidebar-menu-item/sidebar-menu-item.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ export const activeSubSection = () => (
<SidebarMenuItem active>Transmitere și simptome</SidebarMenuItem>
);

export const withTheme = () => (
<>
<SidebarMenuItem
isTitle
theme={{ highlightColor: "#F6DD62", backgroundColor: "#F6F9FC" }}
>
Transmitere și simptome
</SidebarMenuItem>
<SidebarMenuItem
isTitle
active
theme={{ highlightColor: "#F6DD62", backgroundColor: "#F6F9FC" }}
>
Transmitere și simptome
</SidebarMenuItem>
<SidebarMenuItem
theme={{ highlightColor: "#F6DD62", backgroundColor: "#F6F9FC" }}
>
Transmitere și simptome
</SidebarMenuItem>
<SidebarMenuItem
active
theme={{ highlightColor: "#F6DD62", backgroundColor: "#F6F9FC" }}
>
Transmitere și simptome
</SidebarMenuItem>
</>
);

export const sectionTitleWithCallback = () => {
const [data, setData] = useState({});
const documentExample = {
Expand Down
6 changes: 6 additions & 0 deletions src/hooks/useCssVars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { transform } from "lodash";

export const useCssVars = theme =>
transform(theme, (result, cssValue, cssKey) => {
result[`--${cssKey}`] = cssValue;
});

1 comment on commit 88f8b38

@vercel
Copy link

@vercel vercel bot commented on 88f8b38 May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.