PromucFlow_constructor/app/client/src/pages/Editor/WidgetSidebar.tsx

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-10-18 08:16:26 +00:00
import React from "react";
import { connect } from "react-redux";
import WidgetCard from "./WidgetCard";
import styled from "styled-components";
2019-11-25 05:07:27 +00:00
import { WidgetCardProps } from "widgets/BaseWidget";
import { AppState } from "reducers";
import { getWidgetCards } from "selectors/editorSelectors";
2019-10-18 08:16:26 +00:00
type WidgetSidebarProps = {
cards: { [id: string]: WidgetCardProps[] };
};
const MainWrapper = styled.div`
text-transform: capitalize;
2020-01-24 09:54:40 +00:00
padding: 0 10px;
2019-10-18 08:16:26 +00:00
`;
const CardsWrapper = styled.div`
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: ${props => props.theme.spaces[1]}px;
justify-items: stretch;
align-items: stretch;
`;
class WidgetSidebar extends React.Component<WidgetSidebarProps> {
render(): React.ReactNode {
const groups = Object.keys(this.props.cards);
return (
<MainWrapper>
{groups.map((group: string) => (
<React.Fragment key={group}>
<h5>{group}</h5>
<CardsWrapper>
{this.props.cards[group].map((card: WidgetCardProps) => (
<WidgetCard details={card} key={card.key} />
))}
</CardsWrapper>
</React.Fragment>
))}
</MainWrapper>
);
}
}
const mapStateToProps = (state: AppState) => {
return {
cards: getWidgetCards(state),
};
2019-10-18 08:16:26 +00:00
};
2019-11-25 05:07:27 +00:00
export default connect(mapStateToProps, null)(WidgetSidebar);