Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@storybook/theming';
import { Tabs, Icons, IconButton } from '@storybook/components';
const DesktopOnlyIconButton = styled(IconButton)({
// Hides full screen icon at mobile breakpoint defined in app.js
'@media (max-width: 599px)': {
display: 'none',
},
});
class SafeTab extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true });
// eslint-disable-next-line no-console
console.error(error, info);
({ isExpanded = false }) => {
return isExpanded
? {
transform: 'rotateZ(90deg)',
}
: {};
}
);
export type IconProps = ComponentProps & {
className: string; // FIXME: Icons should extended its typing from the native <svg>
isSelected?: boolean;
};
const Icon = styled(Icons)(
{
flex: 'none',
width: 10,
height: 10,
marginRight: 6,
},
({ icon }) => {
if (icon === 'folder') {
return { color: '#774dd7' };
}
if (icon === 'component') {
return { color: '#1ea7fd' };
}
if (icon === 'bookmarkhollow' || (DOCS_MODE && icon === 'document')) {
return { color: '#37d5d3' };
}</svg>
gridTemplateColumns: '1fr 1fr 0px',
}));
export const GridWrapper = styled.div({
display: 'grid',
gridTemplateColumns: '1fr',
gridAutoRows: 'minmax(auto, auto)',
marginBottom: '20px',
});
// Form
export const Description = styled.div({
alignSelf: 'center',
});
export const TextInput = styled(Input)(
({ valid, theme }) =>
valid === 'error'
? {
animation: `${theme.animation.jiggle} 700ms ease-out`,
}
: {},
{
display: 'flex',
width: 80,
flexDirection: 'column',
justifySelf: 'flex-end',
paddingLeft: 4,
paddingRight: 4,
textAlign: 'center',
}
);
display: 'block',
padding: '16px 20px',
borderRadius: 10,
fontSize: theme.typography.size.s1,
fontWeight: theme.typography.weight.bold,
lineHeight: `16px`,
boxShadow: '0 5px 15px 0 rgba(0, 0, 0, 0.1), 0 2px 5px 0 rgba(0, 0, 0, 0.05)',
color: theme.color.inverseText,
backgroundColor:
theme.base === 'light'
? rgba(`${darken(1, theme.background.app)}`, 0.95)
: rgba(`${lighten(1, theme.background.app)}`, 0.95),
textDecoration: 'none',
});
const NotificationLink = styled(Link)(baseStyle);
const Notification = styled.div(baseStyle);
export const NotificationItemSpacer = styled.div({
height: 48,
});
export default function NotificationItem({ notification: { content, link } }) {
return link ? (
{content}
) : (
{content}
);
}
NotificationItem.propTypes = {
notification: PropTypes.shape({
paddingBottom: 4,
paddingRight: 4,
paddingTop: 4,
fontWeight: '400',
} as any);
const Item = styled.div(({ elementWidth }: { elementWidth: number }) => {
const maxWidthBeforeBreak = 407;
return {
flexDirection: elementWidth > maxWidthBeforeBreak ? 'row' : 'inherit',
marginBottom: elementWidth > maxWidthBeforeBreak ? 6 : 12,
display: elementWidth > maxWidthBeforeBreak ? 'flex' : 'block',
};
});
const StyledBadge = styled(Badge)(({ status }: { status: string }) => ({
padding: '2px 8px',
marginBottom: 3,
minWidth: 65,
maxWidth: 'fit-content',
width: '100%',
textAlign: 'center',
}));
const Message = styled.div({
paddingLeft: 6,
paddingRight: 23,
});
const Status = styled.div(({ passes, impact }: { passes: boolean; impact: string }) => ({
display: 'inline-flex',
justifyContent: 'center',
export interface OptionsTypeKnob extends KnobControlConfig {
options: OptionsTypeOptionsProp;
optionsObj: OptionsKnobOptions;
}
export interface OptionsTypeOptionsProp {
[key: string]: T;
}
export interface OptionsTypeProps extends KnobControlProps {
knob: OptionsTypeKnob;
display: OptionsKnobOptionsDisplay;
}
const OptionsSelect = styled(ReactSelect)({
width: '100%',
maxWidth: '300px',
color: 'black',
});
type ReactSelectOnChangeFn =
| { (v: OptionsSelectValueItem): void }
| { (v: OptionsSelectValueItem[]): void };
interface OptionsSelectValueItem {
value: any;
label: string;
}
const serialize: { (value: T): T } = value => value;
const deserialize: { (value: T): T } = value => value;
const StyledOverridden = ({
className,
overrides,
children,
isLandscape,
size,
...props
}) => (
<div>
{children}
</div>
);
const StyledLayout = styled(StyledOverridden)`
display: flex;
flex-direction: ${({ isLandscape }) => (isLandscape ? 'row' : 'column')};
justify-content: space-between;
align-items: stretch;
height: 100%;
label: addon-layout;
`;
export const Layout = ({ className, children }) => (
{({ isLandscape }) => (
{children}
)}
);
import { Form } from '@storybook/components';
const { Button } = Form;
const Swatch = styled.div(({ theme }) => ({
position: 'absolute',
top: '50%',
transform: 'translateY(-50%)',
left: 6,
width: 16,
height: 16,
boxShadow: `${theme.appBorderColor} 0 0 0 1px inset`,
borderRadius: '1rem',
}));
const ColorButton = styled(Button)(({ active }) => ({
zIndex: active ? 3 : 'unset',
}));
const Popover = styled.div({
position: 'absolute',
zIndex: '2',
});
class ColorType extends React.Component {
state = {
displayColorPicker: false,
};
componentDidMount() {
document.addEventListener('mousedown', this.handleWindowMouseDown);
}
boxSizing: 'border-box',
width: '100%',
background: 'transparent',
border: '0 none',
color: theme.mainTextColor,
padding: theme.layoutMargin,
paddingLeft: 0,
outline: 0,
}));
const FilterForm = styled.form(({ theme, focussed }) => ({
borderBottom: focussed ? `1px solid transparent` : '1px solid transparent',
borderBottomColor: focussed ? theme.color.secondary : theme.mainBorderColor,
outline: 0,
}));
const UnstyledRouterLink = styled(RouterLink)({
color: 'inherit',
textDecoration: 'none',
display: 'block',
});
export const Link = ({ id, prefix, children, ...rest }) => (
{({ viewMode }) => (
{children}
)}
);
Link.displayName = 'Link';
Link.propTypes = {
interface DateTypeState {
valid: boolean | undefined;
}
const FlexSpaced = styled.div({
flex: 1,
display: 'flex',
'&& > *': {
marginLeft: 10,
},
'&& > *:first-of-type': {
marginLeft: 0,
},
});
const FlexInput = styled(Form.Input)({ flex: 1 });
const formatDate = (date: Date) => {
const year = `000${date.getFullYear()}`.slice(-4);
const month = `0${date.getMonth() + 1}`.slice(-2);
const day = `0${date.getDate()}`.slice(-2);
return `${year}-${month}-${day}`;
};
const formatTime = (date: Date) => {
const hours = `0${date.getHours()}`.slice(-2);
const minutes = `0${date.getMinutes()}`.slice(-2);
return `${hours}:${minutes}`;
};