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

♻️ Docs/bento accordion #35864

Merged
merged 1 commit into from
Sep 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/amp-accordion/1.0/amp-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {userAssert} from '../../../src/log';
/** @const {string} */
const TAG = 'amp-accordion';

/** @extends {PreactBaseElement<AccordionDef.AccordionApi>} */
/** @extends {PreactBaseElement<BentoAccordionDef.AccordionApi>} */
class AmpAccordion extends BaseElement {
/** @override */
init() {
Expand Down
32 changes: 16 additions & 16 deletions extensions/amp-accordion/1.0/base-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {useDOMHandle} from '#preact/component';
import {useSlotContext} from '#preact/slot';

import {
Accordion,
AccordionContent,
AccordionHeader,
AccordionSection,
BentoAccordion,
BentoAccordionContent,
BentoAccordionHeader,
BentoAccordionSection,
} from './component';

import {devAssert} from '../../../src/log';
Expand All @@ -25,7 +25,7 @@ const CONTENT_SHIM_PROP = '__AMP_C_SHIM';
const SECTION_POST_RENDER = '__AMP_PR';
const EXPAND_STATE_SHIM_PROP = '__AMP_EXPAND_STATE_SHIM';

/** @extends {PreactBaseElement<AccordionDef.AccordionApi>} */
/** @extends {PreactBaseElement<BentoAccordionDef.AccordionApi>} */
export class BaseElement extends PreactBaseElement {
/** @override */
init() {
Expand Down Expand Up @@ -106,18 +106,18 @@ function getState(element, mu, getExpandStateTrigger) {
'role': section.lastElementChild.getAttribute('role') || undefined,
});
return (
<AccordionSection {...sectionProps}>
<AccordionHeader {...headerProps}></AccordionHeader>
<AccordionContent {...contentProps}></AccordionContent>
</AccordionSection>
<BentoAccordionSection {...sectionProps}>
<BentoAccordionHeader {...headerProps}></BentoAccordionHeader>
<BentoAccordionContent {...contentProps}></BentoAccordionContent>
</BentoAccordionSection>
);
});
return dict({'children': children});
}

/**
* @param {!Element} sectionElement
* @param {!AccordionDef.SectionShimProps} props
* @param {!BentoAccordionDef.SectionShimProps} props
* @return {PreactDef.Renderable}
*/
function SectionShim(sectionElement, {children, expanded}) {
Expand All @@ -132,13 +132,13 @@ function SectionShim(sectionElement, {children, expanded}) {

/**
* @param {!Element} element
* @return {function(!AccordionDef.SectionProps):PreactDef.Renderable}
* @return {function(!BentoAccordionDef.SectionProps):PreactDef.Renderable}
*/
const bindSectionShimToElement = (element) => SectionShim.bind(null, element);

/**
* @param {!Element} sectionElement
* @param {!AccordionDef.HeaderShimProps} props
* @param {!BentoAccordionDef.HeaderShimProps} props
* @return {PreactDef.Renderable}
*/
function HeaderShim(
Expand Down Expand Up @@ -185,13 +185,13 @@ function HeaderShim(

/**
* @param {!Element} element
* @return {function(!AccordionDef.HeaderProps):PreactDef.Renderable}
* @return {function(!BentoAccordionDef.HeaderProps):PreactDef.Renderable}
*/
const bindHeaderShimToElement = (element) => HeaderShim.bind(null, element);

/**
* @param {!Element} sectionElement
* @param {!AccordionDef.ContentShimProps} props
* @param {!BentoAccordionDef.ContentShimProps} props
* @param {{current: ?}} ref
* @return {PreactDef.Renderable}
*/
Expand Down Expand Up @@ -222,7 +222,7 @@ function ContentShimWithRef(

/**
* @param {!Element} element
* @return {function(!AccordionDef.ContentProps):PreactDef.Renderable}
* @return {function(!BentoAccordionDef.ContentProps):PreactDef.Renderable}
*/
const bindContentShimToElement = (element) =>
forwardRef(
Expand All @@ -232,7 +232,7 @@ const bindContentShimToElement = (element) =>
);

/** @override */
BaseElement['Component'] = Accordion;
BaseElement['Component'] = BentoAccordion;

/** @override */
BaseElement['detached'] = true;
Expand Down
34 changes: 17 additions & 17 deletions extensions/amp-accordion/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import {animateCollapse, animateExpand} from './animations';
import {useStyles} from './component.jss';

const AccordionContext = Preact.createContext(
/** @type {AccordionDef.AccordionContext} */ ({})
/** @type {BentoAccordionDef.AccordionContext} */ ({})
);

const SectionContext = Preact.createContext(
/** @type {AccordionDef.SectionContext} */ ({})
/** @type {BentoAccordionDef.SectionContext} */ ({})
);

/** @type {!Object<string, boolean>} */
Expand All @@ -41,11 +41,11 @@ const generateSectionId = sequentialIdGenerator();
const generateRandomId = randomIdGenerator(100000);

/**
* @param {!AccordionDef.AccordionProps} props
* @param {{current: ?AccordionDef.AccordionApi}} ref
* @param {!BentoAccordionDef.BentoAccordionProps} props
* @param {{current: ?BentoAccordionDef.AccordionApi}} ref
* @return {PreactDef.Renderable}
*/
function AccordionWithRef(
function BentoAccordionWithRef(
{
animate = false,
as: Comp = 'section',
Expand Down Expand Up @@ -187,7 +187,7 @@ function AccordionWithRef(
useImperativeHandle(
ref,
() =>
/** @type {!AccordionDef.AccordionApi} */ ({
/** @type {!BentoAccordionDef.AccordionApi} */ ({
toggle,
expand,
collapse,
Expand All @@ -197,7 +197,7 @@ function AccordionWithRef(

const context = useMemo(
() =>
/** @type {!AccordionDef.AccordionContext} */ ({
/** @type {!BentoAccordionDef.AccordionContext} */ ({
registerSection,
toggleExpanded,
isExpanded,
Expand All @@ -216,9 +216,9 @@ function AccordionWithRef(
);
}

const Accordion = forwardRef(AccordionWithRef);
Accordion.displayName = 'Accordion'; // Make findable for tests.
export {Accordion};
const BentoAccordion = forwardRef(BentoAccordionWithRef);
BentoAccordion.displayName = 'Accordion'; // Make findable for tests.
export {BentoAccordion};

/**
* @param {string} id
Expand All @@ -243,10 +243,10 @@ function setExpanded(id, value, expandedMap, expandSingleSection) {
}

/**
* @param {!AccordionDef.AccordionSectionProps} props
* @param {!BentoAccordionDef.BentoAccordionSectionProps} props
* @return {PreactDef.Renderable}
*/
export function AccordionSection({
export function BentoAccordionSection({
animate: defaultAnimate = false,
as: Comp = 'section',
children,
Expand Down Expand Up @@ -311,7 +311,7 @@ export function AccordionSection({

const context = useMemo(
() =>
/** @type {AccordionDef.SectionContext} */ ({
/** @type {BentoAccordionDef.SectionContext} */ ({
animate,
contentId,
headerId,
Expand All @@ -333,10 +333,10 @@ export function AccordionSection({
}

/**
* @param {!AccordionDef.AccordionHeaderProps} props
* @param {!BentoAccordionDef.BentoAccordionHeaderProps} props
* @return {PreactDef.Renderable}
*/
export function AccordionHeader({
export function BentoAccordionHeader({
as: Comp = 'div',
children,
'class': className = '',
Expand Down Expand Up @@ -372,10 +372,10 @@ export function AccordionHeader({
}

/**
* @param {!AccordionDef.AccordionContentProps} props
* @param {!BentoAccordionDef.BentoAccordionContentProps} props
* @return {PreactDef.Renderable}
*/
export function AccordionContent({
export function BentoAccordionContent({
as: Comp = 'div',
children,
'class': className = '',
Expand Down
20 changes: 10 additions & 10 deletions extensions/amp-accordion/1.0/component.type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @externs */

/** @const */
var AccordionDef = {};
var BentoAccordionDef = {};

/**
* @typedef {{
Expand All @@ -12,7 +12,7 @@ var AccordionDef = {};
* children: (?PreactDef.Renderable|undefined),
* }}
*/
AccordionDef.AccordionProps;
BentoAccordionDef.BentoAccordionProps;

/**
* @typedef {{
Expand All @@ -24,7 +24,7 @@ AccordionDef.AccordionProps;
* onExpandStateChange: (function(boolean):undefined|undefined),
* }}
*/
AccordionDef.AccordionSectionProps;
BentoAccordionDef.BentoAccordionSectionProps;

/**
* @typedef {{
Expand All @@ -36,7 +36,7 @@ AccordionDef.AccordionSectionProps;
* children: (?PreactDef.Renderable|undefined),
* }}
*/
AccordionDef.AccordionHeaderProps;
BentoAccordionDef.BentoAccordionHeaderProps;

/**
* @typedef {{
Expand All @@ -47,7 +47,7 @@ AccordionDef.AccordionHeaderProps;
* children: (?PreactDef.Renderable|undefined),
* }}
*/
AccordionDef.AccordionContentProps;
BentoAccordionDef.BentoAccordionContentProps;

/**
* This is not a public API, it exists to define properties for reference
Expand All @@ -61,7 +61,7 @@ AccordionDef.AccordionContentProps;
* children: (?PreactDef.Renderable|undefined),
* }}
*/
AccordionDef.HeaderShimProps;
BentoAccordionDef.HeaderShimProps;

/**
* This is not a public API, it exists to define properties for reference
Expand All @@ -73,7 +73,7 @@ AccordionDef.HeaderShimProps;
* children: (?PreactDef.Renderable|undefined),
* }}
*/
AccordionDef.ContentShimProps;
BentoAccordionDef.ContentShimProps;

/**
* @typedef {{
Expand All @@ -84,7 +84,7 @@ AccordionDef.ContentShimProps;
* prefix: (string),
* }}
*/
AccordionDef.AccordionContext;
BentoAccordionDef.AccordionContext;

/**
* @typedef {{
Expand All @@ -97,10 +97,10 @@ AccordionDef.AccordionContext;
* setHeaderId: (function(string)),
* }}
*/
AccordionDef.SectionContext;
BentoAccordionDef.SectionContext;

/** @interface */
AccordionDef.AccordionApi = class {
BentoAccordionDef.BentoAccordionApi = class {
/**
* @param {string|undefined} section
*/
Expand Down