Skip to content

Commit

Permalink
feat: added Accordion to AddressSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnnat committed Oct 5, 2018
1 parent da21da5 commit 81efdca
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions package/src/components/AddressSelect/v1/AddressSelect.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
import React, { Component } from "react";
// import PropTypes from "prop-types";
import PropTypes from "prop-types";
import styled from "styled-components";
// import { applyTheme } from "../../../utils";
import { withComponents } from "@reactioncommerce/components-context";
import { CustomPropTypes } from "../../../utils";

const StyledDiv = styled.div`
color: #333333;
`;
const AddressSelectWrapper = styled.div``;

class AddressSelect extends Component {
static propTypes = {};
static propTypes = {
addressBook: PropTypes.arrayOf(PropTypes.object),
/**
* If you've set up a components context using
* [@reactioncommerce/components-context](https://github.com/reactioncommerce/components-context)
* (recommended), then this prop will come from there automatically. If you have not
* set up a components context or you want to override one of the components in a
* single spot, you can pass in the components prop directly.
*/
components: PropTypes.shape({
Accordion: CustomPropTypes.component.isRequired,
AddressForm: CustomPropTypes.component.isRequired
}).isRequired
};

static defaultProps = {};

addressToString({ address1, address2, city, country, postal, region }) {
const addressString = `${address1}${address2 ? ", " + address2 : ""}, ${city}, ${region} ${postal} ${country}`;
return addressString;
}

renderAddressAccordion = (address) => {
const { components: { Accordion, AddressForm } } = this.props;
const name = `${address.firstName} ${address.lastName}`;
return (
<Accordion label={name} detail={this.addressToString(address)}>
<AddressForm value={address} />
</Accordion>
);
};

render() {
return <StyledDiv>Address Select</StyledDiv>;
const { addressBook } = this.props;
return <AddressSelectWrapper>{addressBook.map(this.renderAddressAccordion)}</AddressSelectWrapper>;
}
}

export default AddressSelect;
export default withComponents(AddressSelect);

0 comments on commit 81efdca

Please sign in to comment.