cinny/src/app/atoms/button/IconButton.jsx

69 lines
1.7 KiB
React
Raw Normal View History

2021-07-28 22:15:52 +09:00
import React from 'react';
import PropTypes from 'prop-types';
import './IconButton.scss';
import RawIcon from '../system-icons/RawIcon';
2021-08-10 20:28:16 +09:00
import Tooltip from '../tooltip/Tooltip';
2021-07-28 22:15:52 +09:00
import { blurOnBubbling } from './script';
import Text from '../text/Text';
const IconButton = React.forwardRef(({
variant, size, type,
tooltip, tooltipPlacement, src,
onClick, tabIndex, disabled, isImage,
Adapt to different device widths (#401) * Now adapting to small screen sizes, needs improvements * Fix that site only gets into mobile mode when resized * - Added navigation event triggered if user requests to return to navigation on compact screens - People drawer wont be shown on compact screens - Still accessible using settings - would be duplicated UI - mobileSize is now compactSize * Put threshold for collapsing the base UI in a shared file * Switch to a more simple solution using CSS media queries over JS - Move back button to the left a bit so it doesnt get in touch with room icon * switch from component-individual-thresholds to device-type thresholds - <750px: Mobile - <900px: Tablet - >900px: Desktop * Make Settings drawer component collapse on mobile * Fix EmojiBoard not showing up and messing up UI when screen is smaller than 360px * Improve code quality; allow passing classNames to IconButton - remove unnessesary div wrappers - use dir.side where appropriate - rename threshold and its mixins to more descriptive names - Rename "OPEN_NAVIGATION" to "NAVIGATION_OPENED" * - follow BEM methology - remove ROOM_SELECTED listener - rename NAVIGATION_OPENED to OPEN_NAVIGATION where appropriate - this does NOT changes that ref should be used for changing visability * Use ref to change visability to avoid re-rendering * Use ref to change visability to avoid re-rendering * Fix that room component is not hidden by default. This resulted in a broken view when application is viewed in mobile size without having selected a room since loading. * fix: leaving a room should bring one back to navigation Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com>
2022-04-24 19:23:10 +09:00
className,
2021-09-02 22:47:33 +09:00
}, ref) => {
const btn = (
2021-07-28 22:15:52 +09:00
<button
ref={ref}
Adapt to different device widths (#401) * Now adapting to small screen sizes, needs improvements * Fix that site only gets into mobile mode when resized * - Added navigation event triggered if user requests to return to navigation on compact screens - People drawer wont be shown on compact screens - Still accessible using settings - would be duplicated UI - mobileSize is now compactSize * Put threshold for collapsing the base UI in a shared file * Switch to a more simple solution using CSS media queries over JS - Move back button to the left a bit so it doesnt get in touch with room icon * switch from component-individual-thresholds to device-type thresholds - <750px: Mobile - <900px: Tablet - >900px: Desktop * Make Settings drawer component collapse on mobile * Fix EmojiBoard not showing up and messing up UI when screen is smaller than 360px * Improve code quality; allow passing classNames to IconButton - remove unnessesary div wrappers - use dir.side where appropriate - rename threshold and its mixins to more descriptive names - Rename "OPEN_NAVIGATION" to "NAVIGATION_OPENED" * - follow BEM methology - remove ROOM_SELECTED listener - rename NAVIGATION_OPENED to OPEN_NAVIGATION where appropriate - this does NOT changes that ref should be used for changing visability * Use ref to change visability to avoid re-rendering * Use ref to change visability to avoid re-rendering * Fix that room component is not hidden by default. This resulted in a broken view when application is viewed in mobile size without having selected a room since loading. * fix: leaving a room should bring one back to navigation Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com>
2022-04-24 19:23:10 +09:00
className={`ic-btn ic-btn-${variant} ${className}`}
2021-07-28 22:15:52 +09:00
onMouseUp={(e) => blurOnBubbling(e, `.ic-btn-${variant}`)}
onClick={onClick}
// eslint-disable-next-line react/button-has-type
type={type}
tabIndex={tabIndex}
disabled={disabled}
2021-07-28 22:15:52 +09:00
>
<RawIcon size={size} src={src} isImage={isImage} />
2021-07-28 22:15:52 +09:00
</button>
2021-09-02 22:47:33 +09:00
);
if (tooltip === null) return btn;
return (
<Tooltip
placement={tooltipPlacement}
content={<Text variant="b2">{tooltip}</Text>}
>
{btn}
</Tooltip>
);
});
2021-07-28 22:15:52 +09:00
IconButton.defaultProps = {
variant: 'surface',
size: 'normal',
type: 'button',
2021-09-02 22:47:33 +09:00
tooltip: null,
2021-07-28 22:15:52 +09:00
tooltipPlacement: 'top',
onClick: null,
tabIndex: 0,
disabled: false,
isImage: false,
Adapt to different device widths (#401) * Now adapting to small screen sizes, needs improvements * Fix that site only gets into mobile mode when resized * - Added navigation event triggered if user requests to return to navigation on compact screens - People drawer wont be shown on compact screens - Still accessible using settings - would be duplicated UI - mobileSize is now compactSize * Put threshold for collapsing the base UI in a shared file * Switch to a more simple solution using CSS media queries over JS - Move back button to the left a bit so it doesnt get in touch with room icon * switch from component-individual-thresholds to device-type thresholds - <750px: Mobile - <900px: Tablet - >900px: Desktop * Make Settings drawer component collapse on mobile * Fix EmojiBoard not showing up and messing up UI when screen is smaller than 360px * Improve code quality; allow passing classNames to IconButton - remove unnessesary div wrappers - use dir.side where appropriate - rename threshold and its mixins to more descriptive names - Rename "OPEN_NAVIGATION" to "NAVIGATION_OPENED" * - follow BEM methology - remove ROOM_SELECTED listener - rename NAVIGATION_OPENED to OPEN_NAVIGATION where appropriate - this does NOT changes that ref should be used for changing visability * Use ref to change visability to avoid re-rendering * Use ref to change visability to avoid re-rendering * Fix that room component is not hidden by default. This resulted in a broken view when application is viewed in mobile size without having selected a room since loading. * fix: leaving a room should bring one back to navigation Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com>
2022-04-24 19:23:10 +09:00
className: '',
2021-07-28 22:15:52 +09:00
};
IconButton.propTypes = {
variant: PropTypes.oneOf(['surface', 'primary', 'positive', 'caution', 'danger']),
2021-07-28 22:15:52 +09:00
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
type: PropTypes.oneOf(['button', 'submit', 'reset']),
2021-09-02 22:47:33 +09:00
tooltip: PropTypes.string,
2021-07-28 22:15:52 +09:00
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
src: PropTypes.string.isRequired,
onClick: PropTypes.func,
tabIndex: PropTypes.number,
disabled: PropTypes.bool,
isImage: PropTypes.bool,
Adapt to different device widths (#401) * Now adapting to small screen sizes, needs improvements * Fix that site only gets into mobile mode when resized * - Added navigation event triggered if user requests to return to navigation on compact screens - People drawer wont be shown on compact screens - Still accessible using settings - would be duplicated UI - mobileSize is now compactSize * Put threshold for collapsing the base UI in a shared file * Switch to a more simple solution using CSS media queries over JS - Move back button to the left a bit so it doesnt get in touch with room icon * switch from component-individual-thresholds to device-type thresholds - <750px: Mobile - <900px: Tablet - >900px: Desktop * Make Settings drawer component collapse on mobile * Fix EmojiBoard not showing up and messing up UI when screen is smaller than 360px * Improve code quality; allow passing classNames to IconButton - remove unnessesary div wrappers - use dir.side where appropriate - rename threshold and its mixins to more descriptive names - Rename "OPEN_NAVIGATION" to "NAVIGATION_OPENED" * - follow BEM methology - remove ROOM_SELECTED listener - rename NAVIGATION_OPENED to OPEN_NAVIGATION where appropriate - this does NOT changes that ref should be used for changing visability * Use ref to change visability to avoid re-rendering * Use ref to change visability to avoid re-rendering * Fix that room component is not hidden by default. This resulted in a broken view when application is viewed in mobile size without having selected a room since loading. * fix: leaving a room should bring one back to navigation Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com>
2022-04-24 19:23:10 +09:00
className: PropTypes.string,
2021-07-28 22:15:52 +09:00
};
export default IconButton;