Skip to content

Commit e6b843b

Browse files
authored
[Beta] Change useState structure, add examples (#4276)
* [Beta] Change useState structure, add examples * Simpler language * Nix when not to use it
1 parent 84742f0 commit e6b843b

File tree

3 files changed

+237
-189
lines changed

3 files changed

+237
-189
lines changed

beta/src/components/Layout/MarkdownPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export function MarkdownPage<
5050
}
5151
if (child.props.mdxType === 'Recipes') {
5252
return {
53-
url: '#recipes',
53+
url: '#' + (child.props.titleId ?? 'examples'),
5454
depth: 0,
55-
text: 'Recipes',
55+
text: child.props.titleText ?? 'Examples',
5656
};
5757
}
5858
if (child.props.mdxType === 'Recap') {

beta/src/components/MDX/Challenges/Challenges.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {IconArrowSmall} from '../../Icon/IconArrowSmall';
1414
interface ChallengesProps {
1515
children: React.ReactElement[];
1616
isRecipes?: boolean;
17+
titleText?: string;
18+
titleId?: string;
1719
}
1820

1921
export interface ChallengeContents {
@@ -66,7 +68,12 @@ const parseChallengeContents = (
6668
return contents;
6769
};
6870

69-
export function Challenges({children, isRecipes}: ChallengesProps) {
71+
export function Challenges({
72+
children,
73+
isRecipes,
74+
titleText = isRecipes ? 'Try out some examples' : 'Try out some challenges',
75+
titleId = isRecipes ? 'examples' : 'challenges',
76+
}: ChallengesProps) {
7077
const challenges = parseChallengeContents(children);
7178
const scrollAnchorRef = React.useRef<HTMLDivElement>(null);
7279

@@ -112,12 +119,12 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
112119
)}>
113120
<div ref={scrollAnchorRef} className="py-2 px-5 sm:px-8 pb-0 md:pb-0">
114121
<H2
115-
id={isRecipes ? 'recipes' : 'challenges'}
122+
id={titleId}
116123
className={cn(
117124
'text-3xl mb-2 leading-10 relative',
118125
isRecipes ? 'text-purple-50 dark:text-purple-30' : 'text-link'
119126
)}>
120-
{isRecipes ? 'Try out some recipes' : 'Try out some challenges'}
127+
{titleText}
121128
</H2>
122129
{challenges.length > 1 && (
123130
<Navigation
@@ -132,8 +139,8 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
132139
<div key={activeChallenge}>
133140
<h3 className="text-xl text-primary dark:text-primary-dark mb-2">
134141
<div className="font-bold block md:inline">
135-
{isRecipes ? 'Recipe' : 'Challenge'} {currentChallenge.order} of{' '}
136-
{challenges.length}
142+
{isRecipes ? 'Example' : 'Challenge'} {currentChallenge.order}{' '}
143+
of {challenges.length}
137144
<span className="text-primary dark:text-primary-dark">: </span>
138145
</div>
139146
{currentChallenge.name}
@@ -179,7 +186,7 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
179186
setShowSolution(false);
180187
}}
181188
active>
182-
Next {isRecipes ? 'Recipe' : 'Challenge'}
189+
Next {isRecipes ? 'Example' : 'Challenge'}
183190
<IconArrowSmall
184191
displayDirection="right"
185192
className="block ml-1.5"

0 commit comments

Comments
 (0)