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(fade-in-out): introducing new components #4608

Merged
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
caea15c
fix(megamenu): fixed uncentered arrow icon in safari
IgnacioBecerra Nov 24, 2020
e0827fd
Revert "fix(megamenu): fixed uncentered arrow icon in safari"
IgnacioBecerra Nov 24, 2020
d7c4f8b
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 24, 2020
370161c
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 25, 2020
7ac3c4e
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Nov 30, 2020
b3bf936
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 1, 2020
f2f28e0
feat(scroll-into-view): introducing new utility
IgnacioBecerra Dec 3, 2020
d697a49
feat(scroll-into-view): adding and removing classes instead
IgnacioBecerra Dec 3, 2020
f2f6b40
feat(scroll-into-view): using prefixes
IgnacioBecerra Dec 3, 2020
65cd0cc
feat(scroll-into-view): updated dependencies
IgnacioBecerra Dec 3, 2020
348cff7
feat(scroll-into-view): dependency fix
IgnacioBecerra Dec 3, 2020
e55580c
feat(scroll-into-view): changed sass file location
IgnacioBecerra Dec 3, 2020
879fe94
fix(scroll-into-view): removed dependency
IgnacioBecerra Dec 3, 2020
a9d195d
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 3, 2020
6e07260
feat(scroll-into-view): slight refactoring
IgnacioBecerra Dec 4, 2020
610ce46
feat(scroll-into-view): removed unneeded dependency
IgnacioBecerra Dec 4, 2020
0b34be4
Merge branch 'master' into scroll-fade-animation
jeffchew Dec 4, 2020
7c23d01
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Dec 4, 2020
ed05f92
feat(scroll-into-view): added story and fixed jsdoc
IgnacioBecerra Dec 4, 2020
461edc1
Merge branch 'scroll-fade-animation' of https://github.com/IgnacioBec…
IgnacioBecerra Dec 4, 2020
8264ddf
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Dec 4, 2020
40bbba9
chore(scroll-into-view): update screenshots
IgnacioBecerra Dec 4, 2020
077b0dd
Merge branch 'scroll-fade-animation' of https://github.com/IgnacioBec…
IgnacioBecerra Dec 4, 2020
e5eedd1
chore(snapshots): more snapshots!
IgnacioBecerra Dec 4, 2020
35eb572
feat(scroll-into-view): added web component story variation
IgnacioBecerra Dec 4, 2020
d62d6d4
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 7, 2020
5392a08
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 7, 2020
90a961a
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 8, 2020
41fbdd5
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 9, 2020
95f4af5
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 10, 2020
72c1a97
feat(scroll-into-view): improved based on feedback
IgnacioBecerra Dec 15, 2020
a9a4511
Merge branch 'master' of https://github.com/IgnacioBecerra/ibm-dotcom…
IgnacioBecerra Dec 15, 2020
0425ce4
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Dec 15, 2020
54c0f5b
feat(scroll-into-view): added variation to web component dotcom shell
IgnacioBecerra Dec 15, 2020
2cffb6f
feat(scroll-into-view): replaced eventlistener for resize observer
IgnacioBecerra Dec 16, 2020
a82d128
Update packages/utilities/src/utilities/scrollIntoView/scrollIntoView.js
IgnacioBecerra Dec 16, 2020
794ec81
feat(scroll-into-view): update parameter to include future options
IgnacioBecerra Dec 16, 2020
67e7e32
Merge branch 'scroll-fade-animation' of https://github.com/IgnacioBec…
IgnacioBecerra Dec 16, 2020
93768f9
chore(scroll-into-view): update snapshots
IgnacioBecerra Dec 16, 2020
671764b
Merge branch 'master' of https://github.com/carbon-design-system/carb…
IgnacioBecerra Dec 16, 2020
8df2faf
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Dec 16, 2020
4671464
chore(scroll-into-view): updated snapshots again
IgnacioBecerra Dec 16, 2020
972fbc2
Update packages/utilities/src/utilities/scrollIntoView/scrollIntoView.js
IgnacioBecerra Dec 17, 2020
7cacbe7
feat(scroll-into-view): changed margin calculation and logo effect
IgnacioBecerra Dec 17, 2020
84b6fe4
fix(scroll-into-view): typecasting as htmlelement
IgnacioBecerra Dec 17, 2020
afa297e
feat(scroll-into-view): refactored code and stories
IgnacioBecerra Dec 17, 2020
1749f5c
chore(snapshots): updated snapshots
IgnacioBecerra Dec 17, 2020
20cc29f
feat(scroll-into-view): using css rules for staggered delays
IgnacioBecerra Dec 18, 2020
3f4450a
feat(fade-in-out): reimplemented into web and react components
IgnacioBecerra Jan 8, 2021
8379ff1
feat(fade-in-out): addressed changes in web component
IgnacioBecerra Jan 8, 2021
39bc570
feat(fade-in-out): addressed changes in react
IgnacioBecerra Jan 8, 2021
e7c06ad
chore(fade-in-out): ignore typescript warning
IgnacioBecerra Jan 8, 2021
e46286c
chore(fade-in-out): updated react snapshot
IgnacioBecerra Jan 8, 2021
43ce5aa
feat(fade-in-out): addressed feedback
IgnacioBecerra Jan 11, 2021
b4291d5
chore(fade-in-out): update snapshots
IgnacioBecerra Jan 12, 2021
79e7913
feat(fade-in-out): component wrapping
IgnacioBecerra Jan 12, 2021
86772a5
feat(fade-in-out): addressed feedback
IgnacioBecerra Jan 12, 2021
b38bd30
feat(fade-in-out): renamed closure variables
IgnacioBecerra Jan 12, 2021
a4683a2
chore(fade-in-out): separated into individual stories
IgnacioBecerra Jan 14, 2021
6a22d06
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Jan 14, 2021
beb0771
chore(fade-in-out): added missing semicolon
IgnacioBecerra Jan 14, 2021
0eb0cd1
chore(fade-in-out): moved scss to components, removed knobs
IgnacioBecerra Jan 14, 2021
c643950
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Jan 14, 2021
b367d52
chore(dotcom-shell): update with new images
IgnacioBecerra Jan 14, 2021
3e1acb0
fix(dotcom-shell): reintroduced heading
IgnacioBecerra Jan 14, 2021
a364613
Merge branch 'master' into scroll-fade-animation
IgnacioBecerra Jan 14, 2021
6604d52
chore(dotcom-shell): reintroduced link list heading
IgnacioBecerra Jan 14, 2021
399aa63
fix(dotcom-shell): updating content item horizontal eyebrow
IgnacioBecerra Jan 14, 2021
9b49564
Merge branch 'master' into scroll-fade-animation
kodiakhq[bot] Jan 14, 2021
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/**
* Copyright IBM Corp. 2016, 2020
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import '@carbon/ibmdotcom-styles/scss/internal/scroll-into-view/_scroll-into-view.scss';
import './dotcom-shell.stories.scss';
import { select, object } from '@storybook/addon-knobs';
import Content from './data/content';
import DotcomShell from '../DotcomShell';
import FadeInOut from '../../FadeInOut/FadeInOut';
import { Micro as footerMicroStory } from '../../Footer/__stories__/Footer.stories.js';
import { Default as footerStory } from '../../Footer/__stories__/Footer.stories.js';
import { WithL1 as l1Story } from '../../Masthead/__stories__/Masthead.stories.js';
Expand All @@ -22,6 +25,26 @@ const footerTypeOptions = {
micro: 'micro',
};

const selectorTargets = `
.bx--content-block__heading,
.bx--content-block__copy,
.bx--leadspace-block__media,
.bx--link-list,
.bx--leadspace-block__cta,
.bx--feature-card-block-large,
.bx--content-group,
.bx--image,
.bx--content-block__cta,
.bx--callout-with-media,
.bx--content-item-horizontal__item,
.bx--logo-grid__logo,
.bx--card-group__cards__col,
.bx--callout-quote,
.bx--cta-section,
.bx--cta-section__cta,
.bx--content-item
`;

export default {
title: 'Components|Dotcom Shell',

Expand Down Expand Up @@ -301,3 +324,47 @@ WithL1.story = {
},
},
};

export const WithFadeAnimationsContinuous = ({ parameters }) => {
const { mastheadProps, footerProps } = parameters?.props?.DotcomShell ?? {};
return (
<DotcomShell mastheadProps={mastheadProps} footerProps={footerProps}>
<main id="main-content">
<div style={{ paddingTop: '6rem' }}>
<FadeInOut selectorTargets={selectorTargets} keepAnimations={true}>
<Content />
</FadeInOut>
</div>
</main>
</DotcomShell>
);
};

WithFadeAnimationsContinuous.story = {
// to avoid jest errors with Intersection Observer
parameters: {
storyshots: { disable: true },
},
};

export const WithFadeAnimationsOnce = ({ parameters }) => {
const { mastheadProps, footerProps } = parameters?.props?.DotcomShell ?? {};
return (
<DotcomShell mastheadProps={mastheadProps} footerProps={footerProps}>
<main id="main-content">
<div style={{ paddingTop: '6rem' }}>
<FadeInOut selectorTargets={selectorTargets}>
<Content />
</FadeInOut>
</div>
</main>
</DotcomShell>
);
};

WithFadeAnimationsOnce.story = {
// to avoid jest errors with Intersection Observer
parameters: {
storyshots: { disable: true },
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

.bx--logo-grid__logo,
.bx--card-group__cards__col,
.bx--content-item-wrapper > .bx--content-item {
&:nth-of-type(3n) {
--dds--fade-in-out-delay: 0;
}
&:nth-of-type(3n + 1) {
--dds--fade-in-out-delay: 250ms;
}
&:nth-of-type(3n + 2) {
--dds--fade-in-out-delay: 500ms;
}
&:nth-of-type(3n + 3) {
--dds--fade-in-out-delay: 750ms;
}
}
200 changes: 200 additions & 0 deletions packages/react/src/components/FadeInOut/FadeInOut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/**
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React, { useCallback, useEffect, useRef } from 'react';
import { breakpoints } from '@carbon/layout';
import PropTypes from 'prop-types';
import settings from 'carbon-components/es/globals/js/settings';
const { prefix } = settings;

/**
* Amount of columns used for calculation.
*
* @private
*/
const _colSpan = 3;
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

/**
* Utility handles fade transition for selected elements.
*
* @example
* import { FadeInOut } from '@carbon/ibmdotcom-react';
* import '@carbon/ibmdotcom-styles/scss/internal/scroll-into-view/_scroll-into-view.scss';
*
* As an example, the function can be called to target all instances of the
* elements in a list:
*
* const list = '.bx--content-block, .bx--content-group';
*
* For default values of 400ms and 'one and done' play:
* <FadeInOut selectorTargets={selectorTargets}>
* // some content
* </FadeInOut>
*
* With 'continuous play' option:
* <FadeInOut selectorTargets={selectorTargets} keepAnimations={true}>
* // some content
* </FadeInOut>
*
* For custom delay time, set within targeted class in the application's CSS code as such:
*
* .bx--content-block {
* --#{$dds-prefix}--fade-in-out-delay: 250ms;
* }
*
*/
const FadeInOut = ({ children, selectorTargets, keepAnimations }) => {
/**
* Outer div component ref for using with query selector.
*
* @private
*/
const _componentRef = useRef(null);
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

/**
* Intersection Observer that watches outer viewport.
*
* @private
*/
const _rootObserver = useRef(null);
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

/**
* Intersection observer that watches the inner viewport.
*
* @private
*/
const _innerObserver = useRef(null);
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

/**
* Resize observer to trigger rootMargin recalculations
*
* @private
*/
const _resizeObserver = useRef(null);
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved

/**
* Create observers upon render and update.
*/
useEffect(() => {
_rootObserver.current = new IntersectionObserver(handleExit);
_resizeObserver.current = new ResizeObserver(handleResize);

if (selectorTargets) {
_componentRef.current.querySelectorAll(selectorTargets).forEach(item => {
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved
_rootObserver?.current.observe(item);
});
}
_resizeObserver.current.observe(document.documentElement);

return () => {
_rootObserver.current.disconnect();
_innerObserver.current.disconnect();
_resizeObserver.current.disconnect();
_rootObserver.current = null;
_innerObserver.current = null;
_resizeObserver.current = null;
};
}, [_componentRef, selectorTargets, handleEntrance, handleResize]);

/**
* Handler to add recalculated rootMargin to a new instance of
* inner observer after clearing old one first.
*
* The calculation is done to retrieve the best fitting top and bottom
* margin for the fade animation to trigger/remove from elements in a
* user's screen.
*
* The resulting value is the optimal point where a user's attention will be
* grabbed by the animation without restricting their view and perception of
* the adopting website. The displayed elements will keep the user's attention
* for a longer time as they scroll down the website.
*
* @private
*/
const handleResize = useCallback(() => {
if (_innerObserver.current) {
_innerObserver.current.disconnect();
_innerObserver.current = null;
}

_innerObserver.current = new IntersectionObserver(handleEntrance, {
rootMargin: `-${(
(document.documentElement.clientHeight * _colSpan) /
breakpoints.max.columns
).toString()}px 0px`,
});

if (selectorTargets) {
_componentRef.current.querySelectorAll(selectorTargets).forEach(item => {
IgnacioBecerra marked this conversation as resolved.
Show resolved Hide resolved
_innerObserver?.current.observe(item);
});
}
}, [_componentRef, _innerObserver, selectorTargets, handleEntrance]);

/**
* Handler to add fade animation to element
*
* @param {*} records observed elements
* @private
*
*/
const handleEntrance = useCallback(
records => {
records.forEach(({ intersectionRatio, target }) => {
if (intersectionRatio > 0) {
target.classList.remove(`${prefix}--fade-out`);
target.classList.add(`${prefix}--fade-in`);
if (!keepAnimations) {
_rootObserver.current.unobserve(target);
_innerObserver.current.unobserve(target);
}
}
});
},
[keepAnimations, _rootObserver, _innerObserver]
);

/**
* Handler to remove element from view
*
* @param {*} records observed elements
* @private
*
*/
function handleExit(records) {
records.forEach(({ intersectionRatio, target }) => {
if (intersectionRatio == 0) {
target.classList.remove(`${prefix}--fade-in`);
target.classList.add(`${prefix}--fade-out`);
}
});
}

return <div ref={_componentRef}>{children}</div>;
};

FadeInOut.propTypes = {
/**
* Component(s) to render within the component
*/
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,

/**
* List of elements to be targeted
*/
selectorTargets: PropTypes.string,

/**
* Boolean to define if animation is continuous
*/
keepAnimations: PropTypes.bool,
};

export default FadeInOut;
7 changes: 7 additions & 0 deletions packages/react/src/components/FadeInOut/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
export { default as FadeInOut } from './FadeInOut';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this file technically belongs in internal, maybe move to components since it is part of a component now. Be sure to update corresponding documentation too.

* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

@import '../../globals/vars';
@import '../../globals/imports';

:root {
--#{$dds-prefix}--fade-in-out-delay: 0s;
}

.#{$prefix}--fade-in {
transition-timing-function: carbon--motion(entrance, expressive);
transition-duration: $duration--slow-01;
transition-delay: var(--#{$dds-prefix}--fade-in-out-delay);
opacity: 1;
}

.#{$prefix}--fade-out {
opacity: 0;
}
2 changes: 1 addition & 1 deletion packages/utilities/src/utilities/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corp. 2016, 2020
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright IBM Corp. 2016, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

/* stylelint-disable selector-type-no-unknown */
dds-logo-grid-item,
dds-card-group-item,
dds-cta-section-item {
&:nth-of-type(3n) {
--dds--fade-in-out-delay: 0;
}
&:nth-of-type(3n + 1) {
--dds--fade-in-out-delay: 250ms;
}
&:nth-of-type(3n + 2) {
--dds--fade-in-out-delay: 500ms;
}
&:nth-of-type(3n + 3) {
--dds--fade-in-out-delay: 750ms;
}
}
/* stylelint-enable selector-type-no-unknown */
Loading