Snacks
v0.0.159
JavaScript組件庫by instacart
請注意:我們仍處於預發行階段。如果您選擇使用零食,請為將來打破變化做好準備。
您可以使用yarn或npm安裝小吃及其依賴性。
yarn add ' ic-snacks 'npm install ' ic-snacks '小吃有一些使用庫所需的同行依賴性。
如果您已經在應用程序的依賴項中列出了這些庫,則無需再次安裝它們。
對於主要組件庫:
如果您想使用動畫:react-transition-group v2.2
有時,在本地進行該項目並查看另一個應用程序中的更改可能會有所幫助。這可以使用NPM鏈接來完成
# From this directory
npm link
# go to the app you are working on
cd ../workspace/my_working_app
# symlink this app
npm link ic-snacks要扭轉過程,您可以執行以下操作
# go to the app you are working on
cd ../workspace/my_working_app
# remove symlink
npm unlink ic-snacksyarn add @instacart/radium
yarn add prop-types
yarn add react
yarn add react-dom
yarn add react-transition-groupnpm install @instacart/radium
npm install prop-types
npm install react
npm install react-dom
npm install react-transition-group使用組件:
import { CircleButton } from 'ic-snacks'
const MyComponent = props => {
const doYes = e => { alert ( 'Snacks are the best!' ) }
const doNo = e => { alert ( 'Wrong choice, choose again.' ) }
return (
< div >
< p > Do you love snacks? </ p >
< CircleButton onClick = { doYes } > Yes </ CircleButton >
< CircleButton onClick = { doNo } > No </ CircleButton >
</ div >
)
}一個更複雜的組件:
import React , { Component } from 'react'
import { NavigationPills } from 'ic-snacks'
const choices = [
{ text : 'bananas' } ,
{ text : 'carrots' } ,
{ text : 'watermelon' } ,
{ text : 'snacks' } ,
{ text : 'kale' } ,
{ text : 'endives' } ,
{ text : 'arugula' } ,
{ text : 'spinach' } ,
{ text : 'potatoes' }
]
class Navigation extends Component {
static state = {
activePill : choices [ 0 ]
}
render ( ) {
return (
< div >
< NavigationPills
pills = { choices }
onPillClick = { ( e , choice ) => {
e . preventDefault ( ) ;
setState ( { activePill : choice . text } )
console . log ( 'Choice clicked!' , choice )
} }
label = 'Favorite healthy snack:'
activePill = { state . activePill }
/>
</ div >
)
}
} https://instacart.github.io/snacks/
請參閱貢獻文檔