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(HelperClasses): add breakpoint helper classes #11786

Merged
merged 8 commits into from
Jul 29, 2022
39 changes: 39 additions & 0 deletions packages/react/src/components/Helpers/HelperClasses.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable no-console */

import React from 'react';
import { usePrefix } from '../../internal/usePrefix';

export default {
title: 'Helpers/BreakpointClasses',
component: BreakpointClasses,
};

export const BreakpointClasses = () => {
const prefix = usePrefix();
return (
<>
<div className={`${prefix}__hidden--sm-only`}>
Only hidden on sm breakpoint
</div>
<div className={`${prefix}__hidden--md-only`}>
Only hidden on md breakpoint
</div>
<div className={`${prefix}__hidden--lg-only`}>
Only hidden on lg breakpoint
</div>
<div className={`${prefix}__hidden--xlg-only`}>
Only hidden on xlg breakpoint
</div>
<div className={`${prefix}__hidden--max-only`}>
Only hidden on max breakpoint
</div>
</>
);
};
43 changes: 43 additions & 0 deletions packages/styles/scss/utilities/_helper-classes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@use '../breakpoint' as *;
@use '../config';

div[class*='hidden--'] {
padding: 2rem 1rem;
}

// Classes that are used to hide elements only at specific breakpoints.
// Helpful for when you would like to hide elements outside of a Grid
.#{config.$prefix}__hidden--sm-only {
background: #8a3ffc;
@include breakpoint-between('sm', 'md') {
display: none;
}
}

.#{config.$prefix}__hidden--md-only {
background: #4589ff;
@include breakpoint-between('md', 'lg') {
display: none;
}
}

.#{config.$prefix}__hidden--lg-only {
background: #42be65;
@include breakpoint-between('lg', 'xlg') {
display: none;
}
}

.#{config.$prefix}__hidden--xlg-only {
background: #f1c21b;
@include breakpoint-between('xlg', 'max') {
display: none;
}
}

.#{config.$prefix}__hidden--max-only {
background: #da1e28;
@include breakpoint-up('max') {
display: none;
}
}
1 change: 1 addition & 0 deletions packages/styles/scss/utilities/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@forward 'component-reset' as component-*;
@forward 'convert' show em, rem;
@forward 'focus-outline';
@forward 'helper-classes';
@forward 'high-contrast-mode';
@forward 'keyframes';
@forward 'placeholder-colors';
Expand Down