优化audio布局

This commit is contained in:
catchonme 2019-07-05 10:01:01 +08:00
parent 9ef9f5b6ce
commit 5b79ae9a8f
3 changed files with 44 additions and 48 deletions

View File

@ -1318,10 +1318,9 @@ $Audio-times-width: px2rem(75px) !default;
$Audio-times-margin: 0 px2rem(5px) !default; $Audio-times-margin: 0 px2rem(5px) !default;
$Audio-process-width: px2rem(80px) !default; $Audio-process-width: px2rem(80px) !default;
$Audio-volume-width: px2rem(20px) !default; $Audio-volume-width: px2rem(20px) !default;
$Audio-volume-height: px2rem(22px) !default; $Audio-volume-height: px2rem(50px) !default;
$Audio-volume-lineHeight: px2rem(50px) !default;
$Audio-volumeControl-width: px2rem(110px) !default; $Audio-volumeControl-width: px2rem(110px) !default;
$Audio-volumeControl-height: px2rem(50px) !default;
$Audio-volumeControl-lineHeight: px2rem(50px) !default;
$Audio-input-width: px2rem(80px) !default; $Audio-input-width: px2rem(80px) !default;
$Audio-track-height: px2rem(6px) !default; $Audio-track-height: px2rem(6px) !default;
$Audio-track-bg: #d7dbdd !default; $Audio-track-bg: #d7dbdd !default;

View File

@ -1,8 +1,5 @@
@mixin input-range { @mixin input-range {
width: $Audio-input-width;
display: inline-block;
-webkit-appearance: none; -webkit-appearance: none;
vertical-align: middle;
outline: none; outline: none;
border: none; border: none;
padding: 0; padding: 0;
@ -37,17 +34,25 @@
display: none; display: none;
} }
.#{$ns}Audio--inline {
display: inline-block;
}
.#{$ns}Audio { .#{$ns}Audio {
box-sizing: border-box; box-sizing: border-box;
height: $Audio-height; height: $Audio-height;
line-height: $Audio-lineHeight; line-height: $Audio-lineHeight;
border: $Audio-border; border: $Audio-border;
display: inline-block;
overflow: hidden;
padding-left: $Audio-item-margin; padding-left: $Audio-item-margin;
overflow: hidden;
&-controls {
display: flex;
flex-direction: row;
align-items: center;
}
&-rates { &-rates {
display: inline-block;
width: $Audio-rate-width; width: $Audio-rate-width;
height: $Audio-rate-height; height: $Audio-rate-height;
text-align: center; text-align: center;
@ -57,17 +62,14 @@
} }
&-rateControl { &-rateControl {
display: inline-block;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
&::after { &::after {
display: inline-block;
clear: both; clear: both;
content: ""; content: "";
} }
.#{$ns}Audio-rateControlItem { .#{$ns}Audio-rateControlItem {
display: inline-block;
width: $Audio-rate-width; width: $Audio-rate-width;
height: $Audio-rate-height; height: $Audio-rate-height;
background: $Audio-rate-bg; background: $Audio-rate-bg;
@ -80,7 +82,6 @@
} }
&-play { &-play {
display: inline-block;
width: $Audio-play-width; width: $Audio-play-width;
cursor: pointer; cursor: pointer;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
@ -91,15 +92,14 @@
} }
&-times { &-times {
display: inline-block;
width: $Audio-times-width; width: $Audio-times-width;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
cursor: default; cursor: default;
flex-shrink: 0;
} }
&-process { &-process {
display: inline-block; flex: auto;
width: $Audio-process-width;
cursor: pointer; cursor: pointer;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
@ -109,9 +109,9 @@
} }
&-volume { &-volume {
display: inline-block;
width: $Audio-volume-width; width: $Audio-volume-width;
height: $Audio-volume-height; height: $Audio-volume-height;
line-height: $Audio-volume-lineHeight;
cursor: pointer; cursor: pointer;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
@ -121,10 +121,12 @@
} }
&-volumeControl { &-volumeControl {
display: inline-block; display: flex;
flex-direction: row;
align-items: center;
width: $Audio-volumeControl-width; width: $Audio-volumeControl-width;
height: $Audio-volumeControl-height; height: $Audio-volume-height;
line-height: $Audio-volumeControl-lineHeight; line-height: $Audio-volume-lineHeight;
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
input[type="range"] { input[type="range"] {
@ -133,7 +135,6 @@
.#{$ns}Audio-volumeControlIcon { .#{$ns}Audio-volumeControlIcon {
margin-right: $Audio-item-margin; margin-right: $Audio-item-margin;
display: inline-block;
cursor: pointer; cursor: pointer;
} }

View File

@ -394,34 +394,30 @@ export class Audio extends React.Component<AudioProps, AudioState> {
} = this.props; } = this.props;
const {muted, src} = this.state; const {muted, src} = this.state;
const body = (
<div className={cx('Audio', className)}>
<audio
className={cx('Audio-original')}
ref={this.audioRef}
onCanPlay={this.load}
autoPlay={autoPlay}
controls
muted={muted}
loop={loop}>
<source src={src} />
</audio>
<div className={cx('Audio-controls')}>
{controls && controls.map((control:string, index:number) => {
control = 'render' + upperFirst(control);
const method:'renderRates'|'renderPlay'|'renderTime'|'renderProcess'|'renderVolume'|'render' = control as any;
return (
<React.Fragment key={index}>
{this[method]()}
</React.Fragment>
)
})}
</div>
</div>
);
return ( return (
inline ? body : <div>{body}</div> <div className={cx('Audio', className, inline ? 'Audio--inline' : '')}>
<audio
className={cx('Audio-original')}
ref={this.audioRef}
onCanPlay={this.load}
autoPlay={autoPlay}
controls
muted={muted}
loop={loop}>
<source src={src} />
</audio>
<div className={cx('Audio-controls')}>
{controls && controls.map((control:string, index:number) => {
control = 'render' + upperFirst(control);
const method:'renderRates'|'renderPlay'|'renderTime'|'renderProcess'|'renderVolume'|'render' = control as any;
return (
<React.Fragment key={index}>
{this[method]()}
</React.Fragment>
)
})}
</div>
</div>
); );
} }
} }