Skip to content

Commit e9efe46

Browse files
committed
show preview on project slug keyword only
also rename styles file to be an actual TS file with the confusing .css.ts extention
1 parent 902e76b commit e9efe46

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

src/components/codeKeywords/codeKeywords.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function makeKeywordsClickable(children: React.ReactNode) {
2727
if (ORG_AUTH_TOKEN_REGEX.test(child)) {
2828
makeOrgAuthTokenClickable(arr, child);
2929
} else if (KEYWORDS_REGEX.test(child)) {
30-
makeProjectKeywordsClickable(arr, child);
30+
const isProjectKeyword = child.startsWith('"___PROJECT_SLUG___"');
31+
makeProjectKeywordsClickable(arr, child, isProjectKeyword);
3132
} else {
3233
arr.push(child);
3334
}
@@ -42,13 +43,14 @@ function makeOrgAuthTokenClickable(arr: ChildrenItem[], str: string) {
4243
));
4344
}
4445

45-
function makeProjectKeywordsClickable(arr: ChildrenItem[], str: string) {
46+
function makeProjectKeywordsClickable(arr: ChildrenItem[], str: string, isProjectKeyword = false) {
4647
runRegex(arr, str, KEYWORDS_REGEX, (lastIndex, match) => (
4748
<KeywordSelector
4849
key={`project-keyword-${lastIndex}`}
4950
index={lastIndex}
5051
group={match[1] || 'PROJECT'}
5152
keyword={match[2]}
53+
showPreview={isProjectKeyword}
5254
/>
5355
));
5456
}

src/components/codeKeywords/keyword.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {MotionProps} from 'framer-motion';
44

5-
import {KeywordSpan} from './styles.css';
5+
import {KeywordSpan} from './styles';
66

77
export function Keyword({
88
initial = {opacity: 0, y: -10, position: 'absolute'},
@@ -17,14 +17,16 @@ export function Keyword({
1717
opacity: {duration: 0.15},
1818
y: {duration: 0.25},
1919
},
20+
showPreview: hasPreview = false,
2021
...props
21-
}: MotionProps) {
22+
}: MotionProps & {showPreview?: boolean}) {
2223
return (
2324
<KeywordSpan
2425
initial={initial}
2526
animate={animate}
2627
exit={exit}
2728
transition={transition}
29+
hasPreview={hasPreview}
2830
{...props}
2931
/>
3032
);

src/components/codeKeywords/keywordSelector.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ import {
2323
PositionWrapper,
2424
ProjectPreview,
2525
Selections,
26-
} from './styles.css';
26+
} from './styles';
2727
import {dropdownPopperOptions} from './utils';
2828

2929
type KeywordSelectorProps = {
3030
group: string;
3131
index: number;
3232
keyword: string;
33+
showPreview: boolean;
3334
};
3435

35-
export function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
36+
export function KeywordSelector({keyword, group, index, showPreview}: KeywordSelectorProps) {
3637
const [isOpen, setIsOpen] = useState(false);
3738
const [referenceEl, setReferenceEl] = useState<HTMLSpanElement | null>(null);
3839
const [dropdownEl, setDropdownEl] = useState<HTMLElement | null>(null);
@@ -146,11 +147,12 @@ export function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
146147
onAnimationStart={() => setIsAnimating(true)}
147148
onAnimationComplete={() => setIsAnimating(false)}
148149
key={currentSelectionIdx}
150+
showPreview={showPreview}
149151
>
150152
{currentSelection[keyword]}
151153
</Keyword>
152154
</AnimatePresence>
153-
{!isOpen && currentSelection?.title && (
155+
{!isOpen && showPreview && currentSelection?.title && (
154156
<ProjectPreview className="no-copy">
155157
{currentSelection.title}
156158
</ProjectPreview>

src/components/codeKeywords/orgAuthTokenCreator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
KeywordDropdown,
2222
PositionWrapper,
2323
Selections,
24-
} from './styles.css';
24+
} from './styles';
2525
import {dropdownPopperOptions} from './utils';
2626

2727
type TokenState =

src/components/codeKeywords/styles.css.ts renamed to src/components/codeKeywords/styles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ export const KeywordIndicator = styled(ArrowDown, {
154154
top: -1px;
155155
`;
156156

157-
export const KeywordSpan = styled(motion.span)`
157+
export const KeywordSpan = styled(motion.span)<{
158+
hasPreview?: boolean;
159+
}>`
158160
grid-row: 1;
159161
grid-column: 1;
160162
display: inline-block;
161-
margin-top: 24px;
163+
margin-top: ${p => (p.hasPreview ? '24px' : '0')};
162164
`;
163165

164166
export const KeywordSearchInput = styled('input')<{dark: boolean}>`

0 commit comments

Comments
 (0)