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

[iphone][playground] Add screen demo using antd-mobile #2

Merged
merged 9 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 59 additions & 40 deletions iphone/src/phone/Device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DynamicIslandMusicPlayer } from '../../dynamic-island/src/MusicPlayer';
import { DynamicIslandPhoneCall } from '../../dynamic-island/src/PhoneCall';
import { shadow } from '../utils/shadow';
import { Pagination } from './Pagination';
import { Symbols } from './Symbols';
import { AppBarBrightness, Symbols } from './Symbols';
import { DEVICE_HEIGHT, DEVICE_WIDTH } from './constants';
import classes from './device.module.scss';
import { APP_ICON_SIZE } from './icons/AppIcon';
Expand All @@ -19,23 +19,27 @@ const SCREEN_CONTENT_WIDTH = Math.floor(APP_CELL_SIZE * 4);

export type DeviceFrameColor = 'purple' | 'silver' | 'black' | 'gold';
export type BasicDeviceProps = {
appBarBrightness: AppBarBrightness;
frameColor: DeviceFrameColor;
apps: GridItemProps[];
dock: GridItemProps[];
backgroundImage?: string;
dynamicIslandProps: Omit<DynamicIslandProps, 'children'>;
children?: React.ReactNode;
};
type DeviceProps = BasicDeviceProps & {
style?: React.CSSProperties;
};

export const Device: React.FC<DeviceProps> = ({
appBarBrightness = 'light',
style,
frameColor,
apps,
dock,
backgroundImage,
dynamicIslandProps,
children,
}) => {
const deviceFrameColorClass =
frameColor === 'purple' ? undefined : `device-${frameColor}`;
Expand Down Expand Up @@ -67,7 +71,12 @@ export const Device: React.FC<DeviceProps> = ({
className={classes.topContainer}
style={{ width: SCREEN_CONTENT_WIDTH - APP_CELL_GAP }}
>
<span className={`${classes.clock} font-sans`}>
<span
className={`${classes.clock} font-sans`}
style={{
color: appBarBrightness === 'light' ? 'black' : 'undefined',
}}
>
{currentTime}
</span>

Expand All @@ -84,45 +93,55 @@ export const Device: React.FC<DeviceProps> = ({
</DynamicIsland>
</div>

<Symbols style={{ marginRight: -APP_CELL_GAP / 4 }} />
</div>
<div
className={classes.gridWrapper}
style={{ marginTop: DEVICE_HEIGHT * 0.0875 }}
>
<div
className={classes.gridContainer}
style={{
width: SCREEN_CONTENT_WIDTH,
gridTemplateColumns: `repeat(auto-fill, ${APP_CELL_SIZE}px)`,
gridTemplateRows: `repeat(auto-fill, ${
DEVICE_WIDTH * (0.016 + 0.15) +
DEVICE_WIDTH * (0.12 * 0.695)
}px)`,
}}
>
{apps.map((appItem, appIndex) => (
<GridItem key={appIndex} {...appItem} />
))}
</div>
</div>
<div className={classes.bottomWrapper}>
<Pagination />
<div
className={classes.bottomContainer}
style={{
height: DEVICE_HEIGHT * 0.11,
padding: `${0.045 * DEVICE_WIDTH}px ${
0.047 * DEVICE_WIDTH
}px`,
backgroundImage: `url(${backgroundImage})`,
}}
>
{dock.slice(0, 4).map((appItem, appIndex) => (
<GridItem dock key={appIndex} {...appItem} />
))}
</div>
<Symbols
appBarBrightness={appBarBrightness}
style={{ marginRight: -APP_CELL_GAP / 4 }}
/>
</div>

{!children ? (
<>
<div
className={classes.gridWrapper}
style={{ marginTop: DEVICE_HEIGHT * 0.0875 }}
>
<div
className={classes.gridContainer}
style={{
width: SCREEN_CONTENT_WIDTH,
gridTemplateColumns: `repeat(auto-fill, ${APP_CELL_SIZE}px)`,
gridTemplateRows: `repeat(auto-fill, ${
DEVICE_WIDTH * (0.016 + 0.15) +
DEVICE_WIDTH * (0.12 * 0.695)
}px)`,
}}
>
{apps.map((appItem, appIndex) => (
<GridItem key={appIndex} {...appItem} />
))}
</div>
</div>
<div className={classes.bottomWrapper}>
<Pagination />
<div
className={classes.bottomContainer}
style={{
height: DEVICE_HEIGHT * 0.11,
padding: `${0.045 * DEVICE_WIDTH}px ${
0.047 * DEVICE_WIDTH
}px`,
backgroundImage: `url(${backgroundImage})`,
}}
>
{dock.slice(0, 4).map((appItem, appIndex) => (
<GridItem dock key={appIndex} {...appItem} />
))}
</div>
</div>
</>
) : (
children
)}
</div>
</div>
<div className="device-stripe"></div>
Expand Down
33 changes: 33 additions & 0 deletions iphone/src/phone/Phone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DivComponent } from '../types/html';
import { BasicDeviceProps, Device } from './Device';

export type PhoneProps = BasicDeviceProps & {
transformScale: number;
};

export const Phone: React.FC<PhoneProps> = ({
transformScale,
...deviceProps
}) => {
return (
<Wrapper>
<Device
style={{
transform: `scale(${transformScale})`,
transformOrigin: 'top center',
}}
{...deviceProps}
/>
</Wrapper>
);
};

const Wrapper: DivComponent = ({ style, ...props }) => (
<div
{...props}
style={{
display: 'flex',
justifyContent: 'center',
}}
/>
);
17 changes: 15 additions & 2 deletions iphone/src/phone/Symbols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ import React from 'react';
import { DivComponent } from '../types/html';
import classes from './symbols.module.scss';

export const Symbols: DivComponent = (props) => {
export type AppBarBrightness = 'light' | 'dark';

export type SymbolsProps = {
appBarBrightness: AppBarBrightness;
};
export const Symbols: DivComponent<SymbolsProps> = ({
appBarBrightness,
...props
}) => {
return (
<div className={classes.wrapper} {...props}>
<div
className={`${classes.wrapper} ${
appBarBrightness === 'light' ? classes.light : classes.dark
}`}
{...props}
>
<div className={classes.container}>
<div className={classes.cellularList}>
<div className={`${classes.cellularItem} ${classes.cellularOne}`} />
Expand Down
34 changes: 1 addition & 33 deletions iphone/src/phone/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1 @@
import { DivComponent } from '../types/html';
import { BasicDeviceProps, Device } from './Device';

export type PhoneProps = BasicDeviceProps & {
transformScale: number;
};

export const Phone: React.FC<PhoneProps> = ({
transformScale,
...deviceProps
}) => {
return (
<Wrapper>
<Device
style={{
transform: `scale(${transformScale})`,
transformOrigin: 'top center',
}}
{...deviceProps}
/>
</Wrapper>
);
};

const Wrapper: DivComponent = ({ style, ...props }) => (
<div
{...props}
style={{
display: 'flex',
justifyContent: 'center',
}}
/>
);
export { Phone, type PhoneProps } from './Phone';
18 changes: 13 additions & 5 deletions iphone/src/phone/symbols.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
width: fit-content;
display: flex;
}
.dark {
--system-color: white;
--system-opacity: rgba(255, 255, 255, 0.66);
}
.light {
--system-color: black;
--system-opacity: rgba(0, 0, 0, 0.66);
}

.container {
display: flex;
Expand All @@ -17,7 +25,7 @@
}

.cellularItem {
background-color: white;
background-color: var(--system-color);
width: 4px;
margin-right: 2.5px;
border-top-left-radius: 1px;
Expand Down Expand Up @@ -48,7 +56,7 @@
padding: 3px;
border: 3px solid transparent;
border-radius: 30px;
border-top-color: white;
border-top-color: var(--system-color);
}

.batteryWrapper {
Expand All @@ -58,21 +66,21 @@
}

.batteryContainer {
border: 1px solid rgba(255, 255, 255, 0.66);
border: 1px solid var(--system-opacity);
width: 34px;
padding: 2px;
border-radius: 6px;
}

.battery {
background-color: white;
background-color: var(--system-color);
width: 40%;
height: 12px;
border-radius: 4px;
}

.batteryElectrode {
background-color: rgba(255, 255, 255, 0.66);
background-color: var(--system-opacity);
height: 7px;
width: 2px;
margin-left: 2px;
Expand Down
1 change: 1 addition & 0 deletions iphone/src/styles/devices.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
position: absolute;
width: 100%;
z-index: 9;
pointer-events: none;
}

.device-iphone-14-pro .device-stripe::after {
Expand Down
4 changes: 3 additions & 1 deletion iphone/src/types/html.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type UListComponent = React.FC<React.HTMLAttributes<HTMLUListElement>>;
export type LIComponent = React.FC<React.HTMLAttributes<HTMLLIElement>>;

export type DivComponent = React.FC<React.HTMLAttributes<HTMLDivElement>>;
export type DivComponent<T = {}> = React.FC<
React.HTMLAttributes<HTMLDivElement> & T
>;
export type HeadingComponent = React.FC<
React.HTMLAttributes<HTMLHeadingElement>
>;
Expand Down
3 changes: 3 additions & 0 deletions playground/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = withPlugins(
compiler: {
styledComponents: true,
},
experimental: {
transpilePackages: ['antd-mobile'],
},
images: {
dangerouslyAllowSVG: true,
domains: ['github.com', 'cho.sh', 'cataas.com', 'mzstatic.com'],
Expand Down
2 changes: 2 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
},
"dependencies": {
"@blazity/next-image-proxy": "^1.0.2",
"antd-mobile": "^5.27.0",
"antd-mobile-icons": "^0.3.0",
"next": "^13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
6 changes: 6 additions & 0 deletions playground/src/components/GlobalStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const GlobalStyle = createGlobalStyle`
background-color: black;
}

body {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC,
Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial,
sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
}

a {
text-decoration: none;
cursor: pointer;
Expand Down
Loading