added centered for angular

This commit is contained in:
klimentru1986 2018-05-11 00:11:07 +03:00
parent 040cdadf2e
commit 974b0ad4f3
2 changed files with 61 additions and 1 deletions

58
addons/centered/src/angular.js vendored Normal file
View File

@ -0,0 +1,58 @@
import styles from './styles';
function getComponentSelector(component) {
// eslint-disable-next-line no-underscore-dangle
return component.__annotations__[0].selector;
}
function getTemplate(metadata) {
let tpl = '';
if (metadata.component) {
const selector = getComponentSelector(metadata.component);
tpl = `<${selector}></${selector}>`;
}
if (metadata.template) {
tpl = metadata.template;
}
return `
<div [ngStyle]="styles.style">
<div [ngStyle]="styles.innerStyle">
${tpl}
</div>
</div>`;
}
function getModuleMetadata(metadata) {
const { moduleMetadata, component } = metadata;
if (component && !moduleMetadata) {
return {
declarations: [metadata.component],
};
}
if (component && moduleMetadata) {
return {
...moduleMetadata,
declarations: [...moduleMetadata.declarations, metadata.component],
};
}
return moduleMetadata;
}
export default function(metadataFn) {
const metadata = metadataFn();
return {
...metadata,
template: getTemplate(metadata),
moduleMetadata: getModuleMetadata(metadata),
props: {
...metadata.props,
styles,
},
};
}

View File

@ -1,7 +1,9 @@
import { window } from 'global';
import ReactCentered from './react';
import VueCentered from './vue';
import AngularCentered from './angular';
const Centered = window.STORYBOOK_ENV === 'vue' ? VueCentered : ReactCentered;
export default Centered;
export const centeredAng = AngularCentered;