Skip to content

Commit 2e38860

Browse files
juristrFrozenPandaz
authored andcommitted
feat(nx-dev): add deepdive callout component
(cherry picked from commit daf5837)
1 parent e4a8edb commit 2e38860

File tree

7 files changed

+75
-109
lines changed

7 files changed

+75
-109
lines changed

docs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ Your content goes here.
9494
{% /callout %}
9595
```
9696

97-
#### Disclosure
97+
#### Deep Dives
9898

99-
A disclosure can be used for less important information that is initially collapsed.
99+
These are special callouts that are collapsed with the intention of containing more deep-dive information about the topic which isn't required to understand right away.
100100

101101
```markdown
102-
{% disclosure title="string" %}
103-
Your content goes here.
104-
{% /disclosure %}
102+
{% callout type="deepdive" title="string" %}
103+
Your deep-dive content goes here.
104+
{% /callout %}
105105
```
106106

107107
#### Cards

docs/nx-cloud/concepts/reduce-waste.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ If we don't use the `nx affected` command in CI, no matter how our repo is struc
251251

252252
Note that the 50% chance of any project being modified is an arbitrary number. If we had picked a lower chance of being modified all the expected values would decrease as well. Every repository is different, but this illustrates that a flatter structure will help speed up your CI pipeline.
253253

254-
{% disclosure title="The Math Behind the Expected Number of Affected Projects" %}
254+
{% callout title="The Math Behind the Expected Number of Affected Projects" type="deepdive" %}
255255

256256
**Definitions:**
257257

@@ -290,7 +290,7 @@ Note that the 50% chance of any project being modified is an arbitrary number. I
290290
**Expected Number of Affected Projects:**
291291
ℙa(1) + ℙa(2) + ℙa(3) = 0.5 + 0.5 + 0.5 = 1.5
292292

293-
{% /disclosure %}
293+
{% /callout %}
294294

295295
## Reduce Wasted Time with Remote Caching
296296

docs/nx-cloud/features/dynamic-agents.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ distribute-on:
3333
large-changeset: 10 linux-medium-js
3434
```
3535

36-
{% callout type="note" title="How is the size of the PR determined?" %}
37-
To determine the size of the PR, Nx Cloud calculates the ratio between the number of [affected projects](/ci/features/affected) and the total number of projects in the workspace. It then categorizes it as small, medium, or large.
36+
{% callout type="deepdive" title="How is the size of the PR determined?" %}
37+
To determine the size of the PR, Nx Cloud calculates the relationship between the number of [affected projects](/ci/features/affected) and the total number of projects in the workspace. It then assigns it to one of the three categories: small, medium, or large.
3838
{% /callout %}
3939

4040
You can then reference it in your CI pipeline configuration:

nx-dev/ui-markdoc/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import { CallToAction } from './lib/tags/call-to-action.component';
1919
import { callToAction } from './lib/tags/call-to-action.schema';
2020
import { Card, Cards, LinkCard } from './lib/tags/cards.component';
2121
import { card, cards, linkCard } from './lib/tags/cards.schema';
22-
import { Disclosure } from './lib/tags/disclosure.component';
23-
import { disclosure } from './lib/tags/disclosure.schema';
2422
import { GithubRepository } from './lib/tags/github-repository.component';
2523
import { githubRepository } from './lib/tags/github-repository.schema';
2624
import { StackblitzButton } from './lib/tags/stackblitz-button.component';
@@ -78,7 +76,6 @@ export const getMarkdocCustomConfig = (
7876
'call-to-action': callToAction,
7977
card,
8078
cards,
81-
disclosure,
8279
'link-card': linkCard,
8380
'github-repository': githubRepository,
8481
'stackblitz-button': stackblitzButton,
@@ -107,7 +104,6 @@ export const getMarkdocCustomConfig = (
107104
CallToAction,
108105
Card,
109106
Cards,
110-
Disclosure,
111107
LinkCard,
112108
CustomLink,
113109
FenceWrapper,
Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
'use client';
2+
3+
import React, { useState, useEffect } from 'react';
4+
import cx from 'classnames';
15
import {
6+
ChevronRightIcon,
7+
ChevronDownIcon,
28
CheckCircleIcon,
39
ExclamationCircleIcon,
410
HandRaisedIcon,
511
InformationCircleIcon,
12+
AcademicCapIcon,
613
} from '@heroicons/react/24/outline';
7-
import cx from 'classnames';
8-
import { ReactNode } from 'react';
914

10-
type CalloutType = 'note' | 'warning' | 'check' | 'caution';
15+
type CalloutType = 'note' | 'warning' | 'check' | 'caution' | 'deepdive';
16+
1117
const typeMap: Record<
1218
CalloutType,
1319
{
@@ -26,7 +32,7 @@ const typeMap: Record<
2632
/>
2733
),
2834
backgroundColor: 'bg-slate-50 dark:bg-slate-800/40',
29-
borderColor: 'ring-slate-100 dark:ring-slate-700',
35+
borderColor: 'border-slate-200 dark:border-slate-700',
3036
titleColor: 'text-slate-600 dark:text-slate-300',
3137
textColor: 'text-slate-700 dark:text-slate-400',
3238
},
@@ -38,7 +44,7 @@ const typeMap: Record<
3844
/>
3945
),
4046
backgroundColor: 'bg-yellow-50 dark:bg-yellow-900/30',
41-
borderColor: 'ring-yellow-100 dark:ring-yellow-900',
47+
borderColor: 'border-yellow-200 dark:border-yellow-800',
4248
titleColor: 'text-yellow-600 dark:text-yellow-400',
4349
textColor: 'text-yellow-700 dark:text-yellow-600',
4450
},
@@ -50,7 +56,7 @@ const typeMap: Record<
5056
/>
5157
),
5258
backgroundColor: 'bg-green-50 dark:bg-green-900/30',
53-
borderColor: 'ring-green-100 dark:ring-green-900',
59+
borderColor: 'border-green-200 dark:border-green-800',
5460
titleColor: 'text-green-600 dark:text-green-400',
5561
textColor: 'text-green-700 dark:text-green-600',
5662
},
@@ -59,43 +65,82 @@ const typeMap: Record<
5965
<HandRaisedIcon className="h-5 w-5 text-red-500" aria-hidden="true" />
6066
),
6167
backgroundColor: 'bg-red-50 dark:bg-red-900/30',
62-
borderColor: 'ring-red-100 dark:ring-red-900',
68+
borderColor: 'border-red-200 dark:border-red-800',
6369
titleColor: 'text-red-600 dark:text-red-400',
6470
textColor: 'text-red-700 dark:text-red-600',
6571
},
72+
deepdive: {
73+
icon: (
74+
<AcademicCapIcon className="h-5 w-5 text-blue-500" aria-hidden="true" />
75+
),
76+
backgroundColor: 'bg-blue-50 dark:bg-blue-900/30',
77+
borderColor: 'border-blue-200 dark:border-blue-800',
78+
titleColor: 'text-white-600 dark:text-white-400',
79+
textColor: 'text-white-700 dark:text-white-600',
80+
},
6681
};
6782

6883
export function Callout({
6984
title,
7085
type,
7186
children,
87+
defaultExpanded = false,
7288
}: {
7389
title: string;
7490
type: CalloutType;
7591
children: ReactNode;
92+
defaultExpanded?: boolean;
7693
}) {
94+
const [isOpen, setIsOpen] = useState(type !== 'deepdive');
7795
const ui = typeMap[type] || typeMap.note;
96+
const isCollapsible = type === 'deepdive';
97+
98+
useEffect(() => {
99+
if (isCollapsible) {
100+
setIsOpen(defaultExpanded);
101+
}
102+
}, [defaultExpanded, isCollapsible]);
103+
104+
const toggleOpen = () => {
105+
if (isCollapsible) {
106+
setIsOpen(!isOpen);
107+
}
108+
};
78109

79-
// We use `<span>`s because we are inside `<p>`s
80110
return (
81-
<span
111+
<div
82112
className={cx(
83-
'my-6 block rounded-md p-4 ring-1',
84-
ui.backgroundColor,
85-
ui.borderColor
113+
'my-6 overflow-hidden rounded-md border',
114+
ui.borderColor,
115+
ui.backgroundColor
86116
)}
87117
>
88-
<span className="flex">
89-
<span className="flex-shrink-0">{ui.icon}</span>
90-
<span className="ml-3">
91-
<span className={cx('mt-0 block text-sm font-medium', ui.titleColor)}>
118+
<div
119+
onClick={toggleOpen}
120+
className={cx(
121+
'flex w-full items-center justify-between p-4',
122+
'transition-colors duration-200 hover:bg-opacity-80',
123+
{ 'cursor-pointer': isCollapsible }
124+
)}
125+
>
126+
<span className="flex items-center">
127+
<span className="flex-shrink-0">{ui.icon}</span>
128+
<span className={cx('ml-3 text-sm font-medium', ui.titleColor)}>
92129
{title}
93130
</span>
94-
<span className={cx('prose-sm mt-2 block', ui.textColor)}>
95-
{children}
96-
</span>
97131
</span>
98-
</span>
99-
</span>
132+
{isCollapsible &&
133+
(isOpen ? (
134+
<ChevronDownIcon className="h-5 w-5" />
135+
) : (
136+
<ChevronRightIcon className="h-5 w-5" />
137+
))}
138+
</div>
139+
{isOpen && (
140+
<div className="px-4 pb-4 pt-0">
141+
<span className={cx('prose-sm block', ui.textColor)}>{children}</span>
142+
</div>
143+
)}
144+
</div>
100145
);
101146
}

nx-dev/ui-markdoc/src/lib/tags/disclosure.component.tsx

Lines changed: 0 additions & 61 deletions
This file was deleted.

nx-dev/ui-markdoc/src/lib/tags/disclosure.schema.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)