Skip to content

Instantly share code, notes, and snippets.

@sebyx07
Last active October 19, 2019 21:51
Show Gist options
  • Save sebyx07/75c154b95f0aed28b26d7721a5a5528f to your computer and use it in GitHub Desktop.
Save sebyx07/75c154b95f0aed28b26d7721a5a5528f to your computer and use it in GitHub Desktop.
JS React => Ruby HYPERSTACK.
Mui = require('@material-ui/core');
Mui.default = Mui;
class HyperComponent
include Hyperstack::Component
include Hyperstack::State::Observable
param_accessor_style :accessors
def __material_component(component_name, **options, &block)
Mui.send(component_name, options, &block)
end
def __material_icon(icon_name, **options)
__material_component("Icon", options) { icon_name.underscore }
end
def method_missing(method_name, *_args, **options, &block)
classified_name = method_name.classify
name_without_icon = method_name.sub("Icon", "")
if classified_name == method_name && `Mui[#{method_name}]`
__material_component(method_name, **options, &block)
elsif name_without_icon != method_name && classified_name == method_name
__material_icon(name_without_icon, **options, &block)
else
super
end
end
end
module Page
class Navbar < HyperComponent
# <AppBar position="static">
# <Toolbar>
# <IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="menu">
# <MenuIcon />
# </IconButton>
# <Typography variant="h6" className={classes.title}>
# News
# </Typography>
# <Button color="inherit">Login</Button>
# </Toolbar>
# </AppBar>
render do
AppBar position: :static do
Toolbar do
IconButton edge: :start, color: :inherit, "aria-label": "menu" do
MenuIcon()
end
Typography(variant: :h6) { "News" }
Typography do
Button(color: :inherit) { "Login" }
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment