Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: add description to component (#493)
Browse files Browse the repository at this point in the history
* feat: add description to component

* fixup! remove unneeded line
  • Loading branch information
tilmx authored and marionebl committed May 30, 2018
1 parent 55ba21d commit 1671e80
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const loadPatternplateMeta = require('@patternplate/load-meta');
export interface PatternCandidate {
artifactPath: string;
declarationPath: string | undefined;
description: string;
displayName: string;
id: string;
sourcePath: string;
Expand Down Expand Up @@ -152,6 +153,7 @@ function analyzePatternExport(
path: ctx.candidate.artifactPath,
pattern: {
contextId,
description: ctx.candidate.description,
exportName,
id,
name: exportName !== 'default' ? exportName : ctx.candidate.displayName,
Expand Down Expand Up @@ -190,6 +192,7 @@ async function findPatternCandidates(path: string): Promise<PatternCandidate[]>
return {
artifactPath: Fs.existsSync(artifactPath) ? artifactPath : undefined,
declarationPath: Fs.existsSync(declarationPath) ? declarationPath : undefined,
description: pattern.manifest.description || '',
displayName: pattern.manifest.displayName || pattern.manifest.name,
id: pattern.id,
sourcePath
Expand Down
33 changes: 29 additions & 4 deletions src/components/pattern-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const StyledPatternListItem = styled.div`
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.15);
border-radius: 3px;
transition: box-shadow 0.2s, color 0.2s;
align-items: center;
color: ${colors.grey20.toString()};
&:hover {
Expand All @@ -52,11 +51,29 @@ const StyledPatternListItem = styled.div`
`;

const StyledIcon = styled(Icon)`
margin-right: 6px;
margin-right: ${getSpace(SpaceSize.XS)}px;
flex: 0 0 ${IconSize.S}px;
`;

const StyledPatternListItemLabel = styled.div`
const StyledPatternListItemContainer = styled.div`
padding: ${getSpace(SpaceSize.XXS)}px 0;
overflow: hidden;
`;

const StyledPatternListItemName = styled.div`
font-size: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

const StyledPatternListItemDescription = styled.div`
padding-top: ${getSpace(SpaceSize.XXS)}px;
font-size: 12px;
color: ${colors.grey50.toString()};
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

export interface PatternFolderViewProps {
Expand Down Expand Up @@ -89,7 +106,7 @@ export const PatternListItem: React.StatelessComponent<PatternListItemProps> = p
color={colors.grey50}
/>
)}
<StyledPatternListItemLabel>{props.children}</StyledPatternListItemLabel>
<StyledPatternListItemContainer>{props.children}</StyledPatternListItemContainer>
</StyledPatternListItem>
);
};
Expand All @@ -98,6 +115,14 @@ export const PatternLabel: React.StatelessComponent = props => (
<StyledPatternLabel>{props.children}</StyledPatternLabel>
);

export const PatternItemLabel: React.StatelessComponent = props => (
<StyledPatternListItemName>{props.children}</StyledPatternListItemName>
);

export const PatternItemDescription: React.StatelessComponent = props => (
<StyledPatternListItemDescription>{props.children}</StyledPatternListItemDescription>
);

const PatternList: React.StatelessComponent = props => (
<StyledPatternList>{props.children}</StyledPatternList>
);
Expand Down
10 changes: 8 additions & 2 deletions src/container/pattern-list/pattern-item-container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { PatternAnchor, PatternListItem } from '../../components';
import {
PatternAnchor,
PatternItemDescription,
PatternItemLabel,
PatternListItem
} from '../../components';
import { Pattern } from '../../model';
import * as React from 'react';
import { ViewStore } from '../../store';
Expand Down Expand Up @@ -60,7 +65,8 @@ export class PatternItemContainer extends React.Component<PatternItemContainerCo
onDoubleClick={e => this.handleDoubleClick(e)}
onDragStart={e => this.handleDragStart(e)}
>
{props.pattern.getName()}
<PatternItemLabel>{props.pattern.getName()}</PatternItemLabel>
<PatternItemDescription>{props.pattern.getDescription()}</PatternItemDescription>
</PatternListItem>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/model/pattern-library/builtins/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export const Box = (context: BuiltInContext): BuiltInResult => {
pattern: new Pattern(
{
contextId: CONTEXT_ID,
description: 'for Flexbox Layouts',
exportName: 'default',
id: patternId,
name: 'Box',
Expand Down
1 change: 1 addition & 0 deletions src/model/pattern-library/builtins/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Page = (context: BuiltInContext): BuiltInResult => {
const pattern = new Pattern(
{
contextId: PATTERN_CONTEXT_ID,
description: '',
exportName: 'default',
id: patternId,
name: 'Page',
Expand Down
1 change: 1 addition & 0 deletions src/model/pattern-library/builtins/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const Placeholder = (context: BuiltInContext): BuiltInResult => {
const pattern = new Pattern(
{
contextId: PATTERN_CONTEXT_ID,
description: 'for Design Drafts',
exportName: 'default',
id: patternId,
name: 'Placeholder',
Expand Down
1 change: 1 addition & 0 deletions src/model/pattern-library/builtins/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const Text = (context: BuiltInContext): BuiltInResult => {
pattern: new Pattern(
{
contextId: PATTERN_CONTEXT_ID,
description: 'for Headlines, Copy and more',
exportName: 'default',
id: patternId,
name: 'Text',
Expand Down
2 changes: 1 addition & 1 deletion src/model/pattern-library/pattern-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class PatternLibrary {

const syntheticFolder = new PatternFolder(
{
name: 'Synthetic',
name: 'Built-In Components',
type: Types.PatternFolderType.Builtin
},
{ patternLibrary }
Expand Down
10 changes: 10 additions & 0 deletions src/model/pattern/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as uuid from 'uuid';

export interface PatternInit {
contextId: string;
description: string;
exportName: string;
id?: string;
name: string;
Expand All @@ -24,6 +25,7 @@ export interface PatternContext {

export class Pattern {
@Mobx.observable private contextId: string;
@Mobx.observable private description: string;
@Mobx.observable private exportName: string;
@Mobx.observable private folder: PatternFolder;
@Mobx.observable private id: string;
Expand All @@ -36,6 +38,7 @@ export class Pattern {

public constructor(init: PatternInit, context: PatternContext) {
this.contextId = init.contextId;
this.description = init.description;
this.exportName = init.exportName;
this.id = init.id || uuid.v4();
this.name = AlvaUtil.guessName(init.name);
Expand All @@ -50,6 +53,7 @@ export class Pattern {
return new Pattern(
{
contextId: serialized.contextId,
description: serialized.description,
exportName: serialized.exportName,
id: serialized.id,
name: serialized.name,
Expand All @@ -70,6 +74,10 @@ export class Pattern {
return this.contextId;
}

public getDescription(): string {
return this.description;
}

public getExportName(): string {
return this.exportName;
}
Expand Down Expand Up @@ -117,6 +125,7 @@ export class Pattern {
public toJSON(): Types.SerializedPattern {
return {
contextId: this.contextId,
description: this.description,
exportName: this.exportName,
id: this.id,
name: this.name,
Expand All @@ -129,6 +138,7 @@ export class Pattern {

public update(pattern: Pattern, context: PatternContext): void {
this.contextId = pattern.getContextId();
this.description = pattern.getDescription();
this.exportName = pattern.getExportName();
this.name = pattern.getName();
this.origin = pattern.getOrigin();
Expand Down
1 change: 1 addition & 0 deletions src/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type SerializedPatternOrigin = 'built-in' | 'user-provided';

export interface SerializedPattern {
contextId: string;
description: string;
exportName: string;
id: string;
name: string;
Expand Down

0 comments on commit 1671e80

Please sign in to comment.