Rift is a swift-ui inspired framework for the web.
This is just a concept
Performance has not been considered for this project, it's just for fun!
npm i rift-ui --save
or
yarn add rift-ui
import {Root, View, Text} from 'rift-ui'
const App = View(
Text('Welcome to my app!', 'h1').fontSize('20px').color('red'),
Text('It rocks...'),
Button('Click Me').onClick(() => console.log('wow'))
)
Root(document.getElementById('root), App)
import {
Component, // Base component class for extending new HTML element types
Root,
View,
Text,
Button,
Img,
ForEach,
If,
Stack,
HStack,
VStack
}
Styling can be chained onto components like so:
Text('My Text')
.color('red')
.borderRadius('200px')
.height('100px')
Functional components are injected with state like so:
const MyComponent = (state = initialState, setState) => {
return Text(state.text).onClick(() => {
setState({
text: 'wow!'
})
})
}
const App = View(
MyComponent
)
const MyComponent = (...props) => {
return Text(props.text)
}
const App = View(
MyComponent(props here...)
)
const MyComponent = (...props) => (state = initialState, setState) => {
// use state here
return Text(props.text)
}
const App = View(
MyComponent(props here...)
)
Current only the onClick event is supported:
Text('My Text')
.onClick(myFunction)
There is a special .attr method for adding attributes to an element:
Text('My Text')
.attr('data-thing', true)
Rift UI currently supports ForEach
and If
components, used like so:
const App = View(
ForEach(array, (item) => Text(Item)),
If(thingIsTrue, Text('It is true!'))
)