Skip to content

Commit 923a0b3

Browse files
committed
refactor: fix InfoPanel text wrapping and alignment on mobile
1 parent fbb9f33 commit 923a0b3

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

components/Panel.tsx

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,35 +144,90 @@ function extractLines(children: ReactNode): ReactNode[][] {
144144
return result;
145145
}
146146

147-
148147
function renderText(type: InfoPanelType, children: ReactNode) {
149148
const lines = extractLines(children);
150149
const [title = [], ...rest] = lines;
151150
const style = typeStyles[type];
152151

152+
const commonTextStyle = 'text-base leading-[1.6] break-words whitespace-pre-line';
153+
153154
return (
154155
<>
155-
<div className={`text-mi flex items-center gap-2 mt-2 mb-1 ${style.titleColor}`}>
156-
{React.cloneElement(style.icon, { className: `w-4 h-4 ${style.titleColor}` })}
157-
{title}
158-
</div>
159-
<div className={`space-y-1 text-mi pl-[1.3rem] ${style.titleColor}`}>
160-
{rest.map((line, i) => (
161-
<div key={i}>{line}</div>
162-
))}
156+
<div className={`flex gap-2 ${style.titleColor}`}>
157+
<div className="flex-shrink-0 relative top-[0.2rem]">
158+
{React.cloneElement(style.icon, {
159+
className: `w-5 h-5 ${style.titleColor}`,
160+
})}
161+
</div>
162+
<div className={commonTextStyle}>
163+
{title}
164+
</div>
163165
</div>
166+
167+
{rest.length > 0 && (
168+
<div className={`mt-2 pl-[1.8rem] space-y-[0.4rem] ${style.titleColor}`}>
169+
{rest.map((line, i) => (
170+
<div key={i} className={commonTextStyle}>
171+
{line}
172+
</div>
173+
))}
174+
</div>
175+
)}
164176
</>
165177
);
166178
}
167179

168180

169-
170-
export default function InfoPanel({ type = 'info', children }: InfoPanelProps) {
181+
export default function InfoPanel({
182+
type = 'info',
183+
children,
184+
}: InfoPanelProps) {
171185
const style = typeStyles[type];
172186

173187
return (
174-
<div className={`my-4 px-4 py-3 rounded-md prose ${style.bg} ${style.border} ${style.text}`}>
188+
<div
189+
className={`my-4 px-4 py-3 rounded-md prose ${style.bg} ${style.border} ${style.text}`}
190+
>
175191
{renderText(type, children)}
176192
</div>
177193
);
178194
}
195+
196+
197+
198+
// function renderText(type: InfoPanelType, children: ReactNode) {
199+
// const lines = extractLines(children);
200+
// const [title = [], ...rest] = lines;
201+
// const style = typeStyles[type];
202+
//
203+
// return (
204+
// <>
205+
// <div
206+
// className={`text-mi mt-2 mb-1 flex flex-col sm:flex-row sm:items-center gap-2 ${style.titleColor}`}
207+
// >
208+
// <div className="flex-shrink-0">
209+
// {React.cloneElement(style.icon, {className: `w-4 h-4 ${style.titleColor}`})}
210+
// </div>
211+
// <div className="break-words whitespace-pre-line leading-snug">
212+
// {title}
213+
// </div>
214+
// </div>
215+
// <div className={`space-y-1 text-mi pl-[1.3rem] ${style.titleColor}`}>
216+
// {rest.map((line, i) => (
217+
// <div key={i}>{line}</div>
218+
// ))}
219+
// </div>
220+
// </>
221+
// );
222+
// }
223+
//
224+
//
225+
// export default function InfoPanel({type = 'info', children}: InfoPanelProps) {
226+
// const style = typeStyles[type];
227+
//
228+
// return (
229+
// <div className={`my-4 px-4 py-3 rounded-md prose ${style.bg} ${style.border} ${style.text}`}>
230+
// {renderText(type, children)}
231+
// </div>
232+
// );
233+
// }

0 commit comments

Comments
 (0)