디렉토리를 이동하고 guest-list.jsx 파일을 신규로 생성한 후 , 아래 내용과 같이 입력한다.
[binrang@binrang components]$ pwd
/home/binrang/br-electrode-component/br-elec-component/src/components
[binrang@binrang components]$ vi guest-list.jsx
import React from "react";
import styles from "../../src/styles/guest-list.css";
const GuestList = ({invitees, toggleGuest}) => {
const renderInvitees = (inviteesArr) => {
return inviteesArr.map((invitee) => (
<div key={invitee.name} className={styles.guestName}>
<input
id={invitee.name}
type="checkbox"
checked={invitee.invited}
onChange={() => toggleGuest(invitee)}/>
<label htmlFor={invitee.name}>
{invitee.name}
</label>
</div>
));
};
return (
<div className={styles.guestList}>
<h1>Guest List:</h1>
{renderInvitees(invitees)}
</div>
);
};
GuestList.propTypes = {
invitees: React.PropTypes.array,
toggleGuest: React.PropTypes.func
};
export default GuestList;
|
2. 위치 : <your-awesome-component>/src/components/render-friend.jsx
디렉토리 확인 후 render-friend.jsx 파일을 신규로 생성 후 아래 코드를 입력한다.
[binrang@binrang components]$ pwd
/home/binrang/br-electrode-component/br-elec-component/src/components
[binrang@binrang components]$ vi render-friend.jsx
import React from "react";
import styles from "../../src/styles/render-friend.css";
import style from "../helpers/graph-styles";
const DEFAULT_SIZE = 15;
const DEGREES_OF_COOL = 360;
const RenderFriend = ({friend, styleObj, className}) => {
const { name, img, profile, friends } = friend;
let { size } = friend;
const parentFriend = { name, img, profile };
size = size ? size : DEFAULT_SIZE;
const bgImg = {backgroundImage: `url(${img})`};
let applyStyle = styleObj
? Object.assign(bgImg, styleObj)
: Object.assign(bgImg, style("single", size));
applyStyle = friends ? style("container", size) : applyStyle;
let applyClass = friends ? styles.join : styles.friend;
applyClass = styleObj ? applyClass : `${applyClass} ${styles.join} ${className || ""}`;
const renderFriends = (friendsArr) => {
const angleVal = (DEGREES_OF_COOL / friendsArr.length);
let rotateVal = 0;
return friendsArr.map((friendObj) => {
rotateVal += angleVal;
return (
<RenderFriend
key={friendObj.name}
friend={friendObj}
styleObj={style("child", size, rotateVal)}/>
);
});
};
return (
<div className={applyClass} style={applyStyle}>
{!!friends && renderFriends(friends)}
{!!friends && <RenderFriend friend={parentFriend} styleObj={style("parent", size)}/>}
</div>
);
};
RenderFriend.propTypes = {
friend: React.PropTypes.object,
styleObj: React.PropTypes.object
};
export default RenderFriend;
|
개발 단계로 첫번째 작업이 끝났다.
참조 URL : low_level_components.html
댓글 없음:
댓글 쓰기