Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): add support for regular weight title #788

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/notifications/.size-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
}
},
"index.cjs.js": {
"bundled": 19391,
"minified": 14041,
"gzipped": 3156
"bundled": 19443,
"minified": 14081,
"gzipped": 3169
},
"index.esm.js": {
"bundled": 18416,
"minified": 13130,
"gzipped": 3055,
"bundled": 18468,
"minified": 13170,
"gzipped": 3067,
"treeshaked": {
"rollup": {
"code": 10050,
"code": 10090,
"import_statements": 282
},
"webpack": {
"code": 12237
"code": 12277
}
}
}
Expand Down
40 changes: 34 additions & 6 deletions packages/notifications/examples/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const alertTitles = {
info: 'Info Alert'
};

const initialState = { type: 'success', showClose: true };
const initialState = { type: 'success', showClose: true, isRegular: false };

<Grid>
<Row>
Expand Down Expand Up @@ -81,11 +81,20 @@ const initialState = { type: 'success', showClose: true };
<Label>Show Close</Label>
</Toggle>
</Field>

<Field className="u-mt-xs">
<Toggle
checked={state.isRegular}
onChange={event => setState({ isRegular: event.target.checked })}
>
<Label>Regular Weight Title</Label>
</Toggle>
</Field>
</Well>
</Col>
<Col md={8}>
<Alert type={state.type}>
<Title>{alertTitles[state.type]}</Title>
<Title isRegular={state.isRegular}>{alertTitles[state.type]}</Title>
Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth
tatsoi tomatillo melon.
{state.showClose && (
Expand Down Expand Up @@ -127,7 +136,8 @@ const notificationTitles = {

const initialState = {
type: undefined,
isMultiLine: false
isMultiLine: false,
isRegular: false
};

<Grid>
Expand Down Expand Up @@ -195,11 +205,20 @@ const initialState = {
<Label>Show Multi-line</Label>
</Toggle>
</Field>

<Field className="u-mt-xs">
<Toggle
checked={state.isRegular}
onChange={event => setState({ isRegular: event.target.checked })}
>
<Label>Regular Weight Title</Label>
</Toggle>
</Field>
</Well>
</Col>
<Col md={8}>
<Notification type={state.type}>
<Title>
<Title isRegular={state.isRegular}>
Notification{notificationTitles[state.type] ? `: ${notificationTitles[state.type]}` : ''}
{state.isMultiLine ? ' (Multi-line)' : ''}
</Title>
Expand Down Expand Up @@ -232,7 +251,8 @@ const { Field, Label, Radio, Toggle } = require('@zendeskgarden/react-forms/src'
const initialState = {
isFloating: false,
isRecessed: false,
isMultiLine: false
isMultiLine: false,
isRegular: false
};

<Grid>
Expand Down Expand Up @@ -263,11 +283,19 @@ const initialState = {
<Label>Show Multi-line</Label>
</Toggle>
</Field>
<Field className="u-mt-xs">
<Toggle
checked={state.isRegular}
onChange={event => setState({ isRegular: event.target.checked })}
>
<Label>Regular Weight Title</Label>
</Toggle>
</Field>
</Well>
</Col>
<Col md={8}>
<Well isRecessed={state.isRecessed} isFloating={state.isFloating}>
<Title>Well {state.isMultiLine && '(Multi-line)'}</Title>
<Title isRegular={state.isRegular}>Well {state.isMultiLine && '(Multi-line)'}</Title>
{state.isMultiLine ? (
<Paragraph>
Nori grape silver beet broccoli kombu beet greens fava bean potato quandong celery.
Expand Down
19 changes: 18 additions & 1 deletion packages/notifications/src/elements/content/Title.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,36 @@ describe('Title', () => {

describe('Types', () => {
it('renders default styling', () => {
const { container } = render(
const { container, getByText } = render(
<Notification>
<Title>title</Title>
</Notification>
);

expect(getByText('title')).toHaveStyleRule(
'font-weight',
`${DEFAULT_THEME.fontWeights.semibold}`
);
expect(container.firstChild).toHaveStyleRule('color', 'inherit', {
modifier: css`
${StyledTitle}
` as any
});
});

it('renders isRegular styling', () => {
const { getByText } = render(
<Notification>
<Title isRegular>title</Title>
</Notification>
);

expect(getByText('title')).toHaveStyleRule(
'font-weight',
`${DEFAULT_THEME.fontWeights.regular}`
);
});

it('renders success styling', () => {
const { container } = render(
<Notification type="success">
Expand Down
11 changes: 8 additions & 3 deletions packages/notifications/src/elements/content/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import React, { HTMLAttributes } from 'react';
import { StyledTitle } from '../../styled';

export interface ITitleProps extends HTMLAttributes<HTMLDivElement> {
/** Style using regular (non-bold) font weight */
isRegular?: boolean;
austingreendev marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Used for Notification titles. Supports all `<div>` props.
* For improved semantics, pass an "h1" or "strong" to the `as` prop.
* Additional styles can be applied to the `as` element to override
* user agent stylesheets.
*/
export const Title = React.forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
(props, ref) => <StyledTitle ref={ref} {...props} />
);
export const Title = React.forwardRef<HTMLDivElement, ITitleProps>((props, ref) => (
<StyledTitle ref={ref} {...props} />
));

Title.displayName = 'Title';
9 changes: 7 additions & 2 deletions packages/notifications/src/styled/content/StyledTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-the

const COMPONENT_ID = 'notifications.title';

export interface IStyledTitleProps {
isRegular?: boolean;
}

/**
* 1. Reset for <h1>, etc.
*/
export const StyledTitle = styled.div.attrs({
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})`
})<IStyledTitleProps>`
margin: 0; /* [1] */
color: ${props => props.theme.colors.foreground};
font-weight: ${props => props.theme.fontWeights.semibold};
font-weight: ${props =>
props.isRegular ? props.theme.fontWeights.regular : props.theme.fontWeights.semibold};
${props => retrieveComponentStyles(COMPONENT_ID, props)};
`;

Expand Down