Skip to content
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

LG-3814: MongoNav LiveExample + CodeDocs #333

Open
wants to merge 19 commits into
base: staging
Choose a base branch
from
Open
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
@lg-private:registry=https://artifactory.corp.mongodb.com/artifactory/api/npm/leafygreen-ui/
//artifactory.corp.mongodb.com/artifactory/api/npm/leafygreen-ui/
//artifactory.corp.mongodb.com/artifactory/api/npm/leafygreen-ui/:username=design-systems-team
//artifactory.corp.mongodb.com/artifactory/api/npm/leafygreen-ui/:[email protected]
//artifactory.corp.mongodb.com/artifactory/api/npm/leafygreen-ui/:always-auth=true
3 changes: 2 additions & 1 deletion components/pages/example/LiveExample.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const liveExampleWrapperStyle = css`
position: relative;
display: flex;
margin-bottom: initial;
overflow: hidden;
// 'overflow: hidden' will stop MongoNav's Menu's from being hidden
spark33 marked this conversation as resolved.
Show resolved Hide resolved
/* overflow: hidden; */
// additional padding is added in storyContainerStyle
padding: ${60 - spacing[3]}px;
`;
Expand Down
6 changes: 4 additions & 2 deletions components/pages/example/LiveExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export const LiveExample = ({
setShowCode(sc => !sc);
};

const storyWrapperStyle = context.meta?.parameters?.wrapperStyle;
const storyContainerOverrideStyles =
context.meta?.parameters?.containerStyles;

// Commented out as this variable is not needed when code examples are not enabled.
// This line was causing issues as the page no longer has access to `window`.
Expand Down Expand Up @@ -109,9 +110,10 @@ export const LiveExample = ({
className={cx(storyContainerStyle, {
[blockContainerStyle]: useBlockWrapperFor.includes(componentName),
})}
style={storyContainerOverrideStyles}
>
{isStateReady(context) && (
<div ref={storyWrapperRef} className={storyWrapperStyle}>
<div ref={storyWrapperRef}>
<LiveExampleDecorator meta={context.meta}>
<context.StoryFn {...context.knobValues} />
</LiveExampleDecorator>
Expand Down
2 changes: 1 addition & 1 deletion layouts/ComponentLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function ComponentLayout({
<div className={mainContentStyle}>
<div className={cx([flexContainer, containerPadding])}>
<H2 as="h1" className={pageHeaderStyle}>
{componentName}
{componentName.replaceAll('-', ' ')}
</H2>
{isMobile && component && session && (
<ComponentLinks
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@leafygreen-ui/marketing-modal": "^4.1.2",
"@leafygreen-ui/menu": "^23.0.0",
"@leafygreen-ui/modal": "^16.0.3",
"@leafygreen-ui/mongo-nav": "^12.2.0",
"@leafygreen-ui/number-input": "^1.0.18",
"@leafygreen-ui/pagination": "^1.0.18",
"@leafygreen-ui/palette": "^4.0.8",
Expand All @@ -88,6 +87,7 @@
"@leafygreen-ui/tokens": "^2.2.0",
"@leafygreen-ui/tooltip": "^11.0.0",
"@leafygreen-ui/typography": "^18.0.1",
"@lg-private/mongo-nav": "^13.1.2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

"@lg-tools/cli": "^0.4.2",
"@lg-tools/storybook": "^0.3.1",
"@mdx-js/loader": "^2.1.0",
Expand Down
25 changes: 22 additions & 3 deletions utils/_getComponentResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import util from 'util';
import markdownToHtml from 'utils/markdownToHtml';
import { CustomComponentDoc } from 'utils/tsdoc.utils';

import { PRIVATE_PACKAGES } from './constants';

// eslint-disable-next-line import/no-anonymous-default-export, react/display-name
export default function () {
return null;
Expand Down Expand Up @@ -46,10 +48,16 @@ export async function getChangelog(
componentName: string,
): Promise<string | null> {
try {
let namespace = '@leafygreen-ui';

if (PRIVATE_PACKAGES.includes(componentName)) {
namespace = '@lg-private';
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const namespace = PRIVATE_PACKAGES.includes(componentName) ? '@lg-private' : '@leafygreen-ui'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this this way since if we were to include lg-chat in the future, we'd want if / else if


const changelogMarkdown = await getFileContent(
path.join(
'./node_modules',
`@leafygreen-ui/${componentName}`,
`${namespace}/${componentName}`,
'/CHANGELOG.md',
),
);
Expand All @@ -62,10 +70,16 @@ export async function getChangelog(

export async function getReadme(componentName: string): Promise<string | null> {
try {
let namespace = '@leafygreen-ui';

if (PRIVATE_PACKAGES.includes(componentName)) {
namespace = '@lg-private';
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same ternary here


const readmeMarkdown = await getFileContent(
path.join(
'./node_modules',
`@leafygreen-ui/${componentName}`,
`${namespace}/${componentName}`,
'/README.md',
),
'utf-8',
Expand All @@ -81,14 +95,19 @@ export async function getReadme(componentName: string): Promise<string | null> {
export async function getTSDoc(
componentName: string,
): Promise<Array<CustomComponentDoc> | null> {
let namespace = '@leafygreen-ui';
if (typeof componentName !== 'string') return null;

if (PRIVATE_PACKAGES.includes(componentName)) {
namespace = '@lg-private';
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ternary here as well

try {
return JSON.parse(
await getFileContent(
path.join(
'./node_modules',
`@leafygreen-ui/${componentName}`,
`${namespace}/${componentName}`,
'/tsdoc.json',
),
'utf-8',
Expand Down
1 change: 1 addition & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PRIVATE_PACKAGES: Array<string> = ['mongo-nav'];
10 changes: 9 additions & 1 deletion utils/getComponentStories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ComponentStoryFn, Meta } from '@storybook/react';

import { PRIVATE_PACKAGES } from './constants';

export type ModuleType = {
default: Meta<any>;
} & {
Expand All @@ -12,8 +14,14 @@ export type ModuleType = {
export async function getComponentStories(
kebabName: string,
): Promise<ModuleType | undefined> {
let namespace = '@leafygreen-ui';

if (PRIVATE_PACKAGES.includes(kebabName)) {
namespace = '@lg-private';
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ternary here too

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could also create a getNamespaceFromPackageName function for future extensibility)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^I like that

try {
return import(`@leafygreen-ui/${kebabName}/stories.js`);
return import(`node_modules/${namespace}/${kebabName}/stories.js`);
} catch (err) {
console.warn(err);
return;
Expand Down
Loading
Loading