-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3573 from klimentru1986/angular_centered
addon-centered for Angular
- Loading branch information
Showing
14 changed files
with
328 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IStory } from '@storybook/angular'; | ||
|
||
declare module '@storybook/addon-centered/angular' { | ||
export function centered(story: IStory): IStory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import fromCentered from './dist/angular'; | ||
|
||
export const centered = fromCentered; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
examples/angular-cli/src/stories/__snapshots__/addon-centered.stories.storyshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Storyshots Addon|Centered centered component 1`] = ` | ||
<storybook-dynamic-app-root | ||
cfr={[Function CodegenComponentFactoryResolver]} | ||
data={[Function Object]} | ||
target={[Function ViewContainerRef_]} | ||
> | ||
<ng-component> | ||
|
||
|
||
<div | ||
ng-reflect-ng-style="[object Object]" | ||
style="position: fixed; top: 0px; left: 0px; bottom: 0px; right: 0px; display: flex; overflow: auto;" | ||
> | ||
|
||
|
||
<div | ||
ng-reflect-ng-style="[object Object]" | ||
style="margin: auto;" | ||
> | ||
|
||
|
||
<storybook-app-root> | ||
|
||
|
||
<div | ||
class="hide" | ||
style="color: red; font-size: 30px; text-align: center;" | ||
> | ||
|
||
This should be hidden, if not - scss is not loaded as needed. | ||
|
||
</div> | ||
|
||
|
||
<div | ||
style="text-align:center" | ||
> | ||
|
||
|
||
<h1> | ||
|
||
Welcome to app! | ||
|
||
</h1> | ||
|
||
|
||
<img | ||
src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOS4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAyNTAgMjUwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNTAgMjUwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPg0KCS5zdDB7ZmlsbDojREQwMDMxO30NCgkuc3Qxe2ZpbGw6I0MzMDAyRjt9DQoJLnN0MntmaWxsOiNGRkZGRkY7fQ0KPC9zdHlsZT4NCjxnPg0KCTxwb2x5Z29uIGNsYXNzPSJzdDAiIHBvaW50cz0iMTI1LDMwIDEyNSwzMCAxMjUsMzAgMzEuOSw2My4yIDQ2LjEsMTg2LjMgMTI1LDIzMCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAJIi8+DQoJPHBvbHlnb24gY2xhc3M9InN0MSIgcG9pbnRzPSIxMjUsMzAgMTI1LDUyLjIgMTI1LDUyLjEgMTI1LDE1My40IDEyNSwxNTMuNCAxMjUsMjMwIDEyNSwyMzAgMjAzLjksMTg2LjMgMjE4LjEsNjMuMiAxMjUsMzAgCSIvPg0KCTxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik0xMjUsNTIuMUw2Ni44LDE4Mi42aDBoMjEuN2gwbDExLjctMjkuMmg0OS40bDExLjcsMjkuMmgwaDIxLjdoMEwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMUwxMjUsNTIuMQ0KCQlMMTI1LDUyLjF6IE0xNDIsMTM1LjRIMTA4bDE3LTQwLjlMMTQyLDEzNS40eiIvPg0KPC9nPg0KPC9zdmc+DQo=" | ||
width="300" | ||
/> | ||
|
||
|
||
</div> | ||
|
||
|
||
<h2> | ||
Here are some links to help you start: | ||
</h2> | ||
|
||
|
||
<ul> | ||
|
||
|
||
<li> | ||
|
||
|
||
<h2> | ||
<a | ||
href="https://angular.io/tutorial" | ||
target="_blank" | ||
> | ||
Tour of Heroes | ||
</a> | ||
</h2> | ||
|
||
|
||
</li> | ||
|
||
|
||
<li> | ||
|
||
|
||
<h2> | ||
<a | ||
href="https://github.com/angular/angular-cli/wiki" | ||
target="_blank" | ||
> | ||
CLI Documentation | ||
</a> | ||
</h2> | ||
|
||
|
||
</li> | ||
|
||
|
||
<li> | ||
|
||
|
||
<h2> | ||
<a | ||
href="https://blog.angular.io//" | ||
target="_blank" | ||
> | ||
Angular blog | ||
</a> | ||
</h2> | ||
|
||
|
||
</li> | ||
|
||
|
||
</ul> | ||
|
||
|
||
|
||
</storybook-app-root> | ||
|
||
|
||
</div> | ||
|
||
|
||
</div> | ||
</ng-component> | ||
</storybook-dynamic-app-root> | ||
`; | ||
|
||
exports[`Storyshots Addon|Centered centered template 1`] = ` | ||
<storybook-dynamic-app-root | ||
cfr={[Function CodegenComponentFactoryResolver]} | ||
data={[Function Object]} | ||
target={[Function ViewContainerRef_]} | ||
> | ||
<ng-component> | ||
|
||
|
||
<div | ||
ng-reflect-ng-style="[object Object]" | ||
style="position: fixed; top: 0px; left: 0px; bottom: 0px; right: 0px; display: flex; overflow: auto;" | ||
> | ||
|
||
|
||
<div | ||
ng-reflect-ng-style="[object Object]" | ||
style="margin: auto;" | ||
> | ||
|
||
|
||
<storybook-button-component | ||
_nghost-c5="" | ||
ng-reflect-text="Hello Button" | ||
> | ||
|
||
|
||
<button | ||
_ngcontent-c5="" | ||
> | ||
Hello Button | ||
</button> | ||
|
||
|
||
</storybook-button-component> | ||
|
||
|
||
</div> | ||
|
||
|
||
</div> | ||
</ng-component> | ||
</storybook-dynamic-app-root> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.