-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
addon-centered for Angular #3573
Merged
Hypnosphi
merged 12 commits into
storybookjs:master
from
klimentru1986:angular_centered
May 13, 2018
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
040cdad
fix addon_support error
klimentru1986 974b0ad
added centered for angular
klimentru1986 4f10573
Merge branch 'upstr_master' into angular_centered
klimentru1986 5ed54dc
added addon centered examples
klimentru1986 c689a1b
documentation updated
klimentru1986 f0341a8
snapshots updated
klimentru1986 009f6cd
yarn test --cli --update
klimentru1986 3475f43
rename centeredAng to ngCentered
klimentru1986 44eb393
import { centered } from '@storybook/addon-centered/angular';
klimentru1986 4d6648d
yarn test --cli --update
klimentru1986 32085d7
Merge branch 'master' into angular_centered
klimentru1986 55ac4d1
update angular example package.json after merge master
klimentru1986 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ngCentered = AngularCentered; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mithril and html have their own entry points (
@storybook/addon-centered/<framework>
) instead and it seems a better approach, because that way you only bring things relevant to particular framework in preview bundle. Vue exports should probably be refactored in that way as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done