Skip to content

Commit 35858ae

Browse files
emersonlaurentinoCompuIves
authored andcommitted
fix embed title (codesandbox#911)
* fix(embed): dynamic height when long title on sidebar * fix(embed): adding white space when title is long * chore(embed): title as variable to use in title attribute
1 parent dc0dadd commit 35858ae

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed

packages/app/src/embed/components/Header/elements.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,38 @@ export const MenuIcon = styled(MenuIconSVG)`
2222
z-index: 10;
2323
`;
2424

25-
export const RightAligned = styled.div`
26-
position: absolute;
27-
right: 1rem;
28-
top: 0;
29-
bottom: 0;
25+
export const LeftAligned = styled.div`
26+
position: relative;
27+
display: flex;
28+
width: calc(50% - 100px);
3029
height: 100%;
30+
align-items: center;
31+
justify-content: flex-start;
32+
`;
33+
export const CenterAligned = styled.div`
34+
position: relative;
3135
display: flex;
36+
width: 200px;
37+
height: 100%;
38+
align-items: center;
3239
justify-content: center;
3340
`;
3441

42+
export const RightAligned = styled.div`
43+
position: relative;
44+
display: flex;
45+
width: calc(50% - 100px);
46+
height: 100%;
47+
align-items: center;
48+
justify-content: flex-end;
49+
`;
50+
3551
export const Title = styled.div`
52+
white-space: nowrap;
53+
text-overflow: ellipsis;
54+
overflow: hidden;
55+
flex: 1;
56+
3657
@media (max-width: 450px) {
3758
display: none;
3859
}

packages/app/src/embed/components/Header/index.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// @flow
22
import * as React from 'react';
3-
43
import type { Sandbox } from 'common/types';
5-
64
import ModeIcons from 'app/components/ModeIcons';
75
import EditorLink from '../EditorLink';
86

9-
import { Container, MenuIcon, RightAligned, Title } from './elements';
7+
import {
8+
Container,
9+
MenuIcon,
10+
Title,
11+
RightAligned,
12+
CenterAligned,
13+
LeftAligned,
14+
} from './elements';
1015

1116
type Props = {
1217
sandbox: Sandbox,
@@ -27,17 +32,23 @@ function Header({
2732
setMixedView,
2833
toggleSidebar,
2934
}: Props) {
35+
const sandboxTitle = sandbox.title || sandbox.id;
36+
3037
return (
3138
<Container>
32-
<MenuIcon onClick={toggleSidebar} />
33-
<Title>{sandbox.title || sandbox.id}</Title>
34-
<ModeIcons
35-
showEditor={showEditor}
36-
showPreview={showPreview}
37-
setEditorView={setEditorView}
38-
setPreviewView={setPreviewView}
39-
setMixedView={setMixedView}
40-
/>
39+
<LeftAligned>
40+
<MenuIcon onClick={toggleSidebar} />
41+
<Title title={sandboxTitle}>{sandboxTitle}</Title>
42+
</LeftAligned>
43+
<CenterAligned>
44+
<ModeIcons
45+
showEditor={showEditor}
46+
showPreview={showPreview}
47+
setEditorView={setEditorView}
48+
setPreviewView={setPreviewView}
49+
setMixedView={setMixedView}
50+
/>
51+
</CenterAligned>
4152
<RightAligned>
4253
<EditorLink small sandbox={sandbox} />
4354
</RightAligned>

packages/app/src/embed/components/Sidebar/elements.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const Title = styled.h2`
1616
padding: 0 1rem;
1717
margin: 0;
1818
font-size: 1rem;
19-
line-height: 3rem;
20-
height: 3rem;
19+
margin-top: 1rem;
20+
margin-bottom: 1rem;
2121
vertical-align: middle;
2222
box-sizing: border-box;
2323
`;

packages/app/src/embed/components/Sidebar/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ function Sidebar({ sandbox, setCurrentModule, currentModule }: Props) {
5656

5757
npmDependencies = npmDependencies || {};
5858

59+
const sandboxTitle = sandbox.title || sandbox.id;
60+
5961
return (
6062
<Container>
6163
<Item>
62-
<Title>{sandbox.title || sandbox.id}</Title>
64+
<Title title={sandboxTitle}>{sandboxTitle}</Title>
6365
{sandbox.author && (
6466
<Author>
6567
Made by <strong>{sandbox.author.username}</strong>

0 commit comments

Comments
 (0)