// @flow
/* eslint-disable import/prefer-default-export */
export type ButtonProps = {
type?: 'button' | 'reset' | 'submit',
design: 'primary' | 'secondary',
className?: string,
children?: Array<HTMLElement>,
onClick?: () => void,
onFocus?: () => void,
onmouseover?: () => void,
onmouseout?: () => void,
}
// @flow
import React from 'react';
import type { ButtonProps } from './ButtonProps';
import './Button.css';
/* eslint-disable flowtype/space-after-type-colon */
const Button = ({
design = 'primary',
className = 'btn',
type = 'button',
children } :ButtonProps) =>
<button className={[`${design} ${className}`]} type={type}>
{children}
</button>;
export default Button;
// @flow
import React from 'react';
import Button from './Button.jsx';
import type { ButtonProps } from './ButtonProps';
import Icon from '../Icons/Icon.jsx';
import type { IconProps } from '../Icons/IconProps';
type IconButtonProps = ButtonProps & IconProps;
const IconButton = (props: IconButtonProps) =>
<Button
design={props.design}
onClick={props.onClick}
className={`iconBtn ${props.className}`}
>
<Icon glyph={props.glyph} />
</Button>;
export default IconButton;
My question is, how would Elm/FP handle this?
I mean, unless in missing something...
fancyButton : { label : String, icon : String } -> Html msg
fancyButton { label, icon } =
-- Implementation goes here
`elm-mdl` is doing it that way because it is trying to follow how Google's material library works, and since there is no way to introspect into the virtualnode's to change how they act then it has to wrap things up in that pattern, I.E., VirtualNode limitations and Html.Attributes limitations require it to be this noisy. :-)
`elm-mdl` is doing it that way because it is trying to follow how Google's material library works, and since there is no way to introspect into the virtualnode's to change how they act then it has to wrap things up in that pattern, I.E., VirtualNode limitations and Html.Attributes limitations require it to be this noisy. :-)Yeah, elm-mdl has very specific and unusual design goals (in part because of ways MDL differs from other UI frameworks, and in part because of the author's goal for how to present MDL in a DSL) that make it substantially different from every other project in the Elm world...I would not look at its design and think "ah, this is probably what I want to do for my project!" because the opposite is far more likely. :)
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
I hope I can shed a bit more light here.
The following concepts are all currently frowned upon in React (not that it matters here, just illustrating a point)
- extending classes
- mixins
- traits (ahem - https://github.com/facebook/flow/issues/2135)
- decorators
In favor of
- "higher-order components" (aka over complicated function factories)
- "functions as children", which seems like a useful concept until you try it
- "container components" - AKA view renderers
Given this breadth of approaches, what does Elm and FP suggest as a best practice for composing shared behaviors, children, interfaces (in OOP-speak), mixins, etc?
Hadn't noticed this section in the guide before. Great explanation