Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | 29x 29x 29x 29x 419x 419x 15x 15x 15x 15x 419x 29x 29x 29x 29x 29x | import React from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; import { lucidClassNames } from '../../util/style-helpers'; import { StandardProps, Overwrite } from '../../util/component-types'; const cx = lucidClassNames.bind('&-Button'); const { arrayOf, bool, func, node, oneOf, oneOfType, string } = PropTypes; export interface IButtonPropsRaw extends StandardProps { /** * Disables the Button by greying it out * * @default false **/ isDisabled: boolean; /** * Activates the Button by giving it a "pressed down" look * * @default false **/ isActive: boolean; /** * Set this to `true` if you want the Button to only contain an icon. * * @default false * */ hasOnlyIcon: boolean; /** Style variations of the Button */ kind?: 'primary' | 'link' | 'danger' | 'invisible'; /** Size variations of the Button */ size?: 'short' | 'small' | 'large'; /** Called when the user clicks the \`Button\`. */ onClick: ({ event, props, }: { event: React.MouseEvent<HTMLButtonElement>; props: IButtonProps; }) => void; /** * Form element type variations of Button. Passed through to DOM Button. * * @default "button" * */ type: 'submit' | 'reset' | 'button'; } export type IButtonProps = Overwrite< React.DetailedHTMLProps< React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement >, IButtonPropsRaw >; const defaultProps = { isDisabled: false, isActive: false, onClick: _.noop, type: 'button' as const, hasOnlyIcon: false, }; /** Button */ export const Button = (props: IButtonProps): React.ReactElement => { const { isDisabled, isActive, onClick, hasOnlyIcon, kind, size, className, children, type, ...passThroughs } = props; const buttonRef = React.createRef<HTMLButtonElement>(); function handleClick(event: React.MouseEvent<HTMLButtonElement>): void { if (!isDisabled) { // required to correctly apply the focus state in Safari and Firefox // (still valid 2019-07-22) if (buttonRef.current) { buttonRef.current.focus(); } onClick({ event, props: props }); } } return ( <button {...passThroughs} ref={buttonRef} className={cx( '&', { '&-is-disabled': isDisabled, '&-is-active': isActive, '&-primary': kind === 'primary', '&-link': kind === 'link', '&-invisible': kind === 'invisible', '&-danger': kind === 'danger', '&-short': size === 'short', '&-small': size === 'small', '&-large': size === 'large', '&-has-only-icon': hasOnlyIcon, }, className )} onClick={handleClick} disabled={isDisabled} type={type} > <span className={cx('&-content')}>{children}</span> </button> ); }; Button.defaultProps = defaultProps; Button.displayName = 'Button'; Button.peek = { description: `A basic button. Any props that are not explicitly called out below will be passed through to the native \`Button\` component.`, categories: ['controls', 'buttons'], }; Button.propName = 'Button'; Button.propTypes = { /** Disables the Button by greying it out */ isDisabled: bool, /** Activates the Button by giving it a "pressed down" look */ isActive: bool, /** Class names that are appended to the defaults */ className: string, /** Set this to \`true\` if you want the Button to only contain an icon. */ hasOnlyIcon: bool, /** Any valid React children */ children: oneOfType([node, arrayOf(node)]), /** Style variations of the Button */ kind: oneOf(['primary', 'link', 'danger', 'invisible']), /** Size variations of the Button */ size: oneOf(['short', 'small', 'large']), /** Called when the user clicks the \`Button\`. */ onClick: func, /** Form element type variations of Button. Passed through to DOM Button. */ type: string, }; export default Button; |