Skip to content

Commit

Permalink
Bento: Split amp-fit-text into new file structure (ampproject#32343)
Browse files Browse the repository at this point in the history
* Bento: Split amp-fit-text into new file structure

Per https://docs.google.com/document/d/1uJdH836Q8U5nhtCfVWc24kha2BNxU-Nkp-5riSgyI3k/edit, we'll need to split AMP components into separate files so they may be individually compiled into the npm package's modules.

* Fix broken import

Co-authored-by: Caroline Liu <[email protected]>

Co-authored-by: Caroline Liu <[email protected]>
  • Loading branch information
jridgewell and caroqliu authored Feb 2, 2021
1 parent 4760fba commit edbf23d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
20 changes: 2 additions & 18 deletions extensions/amp-fit-text/1.0/amp-fit-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import {BaseElement} from './base-element';
import {CSS} from '../../../build/amp-fit-text-1.0.css';
import {FitText} from './fit-text';
import {PreactBaseElement} from '../../../src/preact/base-element';
import {isExperimentOn} from '../../../src/experiments';
import {userAssert} from '../../../src/log';

/** @const {string} */
const TAG = 'amp-fit-text';

class AmpFitText extends PreactBaseElement {
class AmpFitText extends BaseElement {
/** @override */
isLayoutSupported(layout) {
userAssert(
Expand All @@ -35,21 +34,6 @@ class AmpFitText extends PreactBaseElement {
}
}

/** @override */
AmpFitText['Component'] = FitText;

/** @override */
AmpFitText['props'] = {
'minFontSize': {attr: 'min-font-size', type: 'number'},
'maxFontSize': {attr: 'max-font-size', type: 'number'},
};

/** @override */
AmpFitText['passthrough'] = true;

/** @override */
AmpFitText['layoutSizeDefined'] = true;

AMP.extension(TAG, '1.0', (AMP) => {
AMP.registerElement(TAG, AmpFitText, CSS);
});
35 changes: 35 additions & 0 deletions extensions/amp-fit-text/1.0/base-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2020 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {FitText} from './component';
import {PreactBaseElement} from '../../../src/preact/base-element';

export class BaseElement extends PreactBaseElement {}

/** @override */
BaseElement['Component'] = FitText;

/** @override */
BaseElement['props'] = {
'minFontSize': {attr: 'min-font-size', type: 'number'},
'maxFontSize': {attr: 'max-font-size', type: 'number'},
};

/** @override */
BaseElement['passthrough'] = true;

/** @override */
BaseElement['layoutSizeDefined'] = true;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as Preact from '../../../src/preact';
import * as styles from './fit-text.css';
import * as styles from './component.css';
import {ContainWrapper} from '../../../src/preact/component';
import {px, resetStyles, setStyle, setStyles} from '../../../src/style';
import {toWin} from '../../../src/types';
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-fit-text/1.0/storybook/Basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as Preact from '../../../../src/preact';
import {FitText} from '../fit-text';
import {FitText} from '../component';
import {number, text, withKnobs} from '@storybook/addon-knobs';
import {withA11y} from '@storybook/addon-a11y';

Expand Down

0 comments on commit edbf23d

Please sign in to comment.